mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-06 07:53:41 +00:00
cd2694e85f
hts221: Add support for hts221.go
37 lines
629 B
Go
37 lines
629 B
Go
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/hts221"
|
|
)
|
|
|
|
func main() {
|
|
|
|
machine.I2C1.Configure(machine.I2CConfig{
|
|
SCL: machine.P0_15, // SCL1 on Nano 33 BLE Sense
|
|
SDA: machine.P0_14, // SDA1 on Nano 33 BLE Sense
|
|
Frequency: machine.TWI_FREQ_400KHZ,
|
|
})
|
|
|
|
sensor := hts221.New(machine.I2C1)
|
|
|
|
if !sensor.Connected() {
|
|
println("HTS221 not connected!")
|
|
return
|
|
}
|
|
|
|
sensor.Configure() // power on and calibrate
|
|
|
|
for {
|
|
|
|
h, _ := sensor.ReadHumidity()
|
|
t, _ := sensor.ReadTemperature()
|
|
println("h =", float32(h)/100.0, "% / t =", float32(t)/1000.0, "*C")
|
|
time.Sleep(time.Second)
|
|
|
|
}
|
|
|
|
}
|