1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/examples/raspi_sht3x.go
Marc-Antoine Ruel 50d5869808 Fix go test ./...
Make all examples to not be built by default by adding the build tag 'example'.
Some files were automatically reformatted by goimports upon saving.
2017-03-13 11:01:39 -04:00

40 lines
674 B
Go

// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/raspi"
)
func main() {
r := raspi.NewAdaptor()
sht3x := i2c.NewSHT3xDriver(r)
work := func() {
sht3x.Units = "F"
sht3x.Start()
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,
)
robot.Start()
}