2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-03-13 23:01:39 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-01-03 17:21:09 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/raspi"
|
2017-01-03 17:21:09 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
r := raspi.NewAdaptor()
|
|
|
|
sht3x := i2c.NewSHT3xDriver(r)
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
sht3x.Units = "F"
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := sht3x.Start(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-01-03 17:21:09 +08:00
|
|
|
sn, err := sht3x.SerialNumber()
|
|
|
|
fmt.Printf("Serial Number: 0x%08x, err: %v\n", sn, err)
|
|
|
|
|
|
|
|
gobot.Every(5*time.Second, func() {
|
|
|
|
temp, rh, err := sht3x.Sample()
|
|
|
|
fmt.Printf("Temp: %f F, Relative Humidity: %f, err: %v\n", temp, rh, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("SHT3xbot",
|
|
|
|
[]gobot.Connection{r},
|
|
|
|
[]gobot.Device{sht3x},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-01-03 17:21:09 +08:00
|
|
|
}
|