tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/sht4x/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "machine" 6 "time" 7 8 "tinygo.org/x/drivers/sht4x" 9 ) 10 11 func main() { 12 machine.I2C0.Configure(machine.I2CConfig{}) 13 sensor := sht4x.New(machine.I2C0) 14 15 for { 16 temp, humidity, _ := sensor.ReadTemperatureHumidity() 17 t := fmt.Sprintf("%.2f", float32(temp)/1000) 18 h := fmt.Sprintf("%.2f", float32(humidity)/100) 19 println("Temperature: ", t, "°C") 20 println("Humidity: ", h, "%") 21 time.Sleep(2 * time.Second) 22 } 23 }