mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
5888bb2ded
sht4x: implemented driver
24 lines
445 B
Go
24 lines
445 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/sht4x"
|
|
)
|
|
|
|
func main() {
|
|
machine.I2C0.Configure(machine.I2CConfig{})
|
|
sensor := sht4x.New(machine.I2C0)
|
|
|
|
for {
|
|
temp, humidity, _ := sensor.ReadTemperatureHumidity()
|
|
t := fmt.Sprintf("%.2f", float32(temp)/1000)
|
|
h := fmt.Sprintf("%.2f", float32(humidity)/100)
|
|
println("Temperature: ", t, "°C")
|
|
println("Humidity: ", h, "%")
|
|
time.Sleep(2 * time.Second)
|
|
}
|
|
}
|