1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-02 22:17:12 +08:00
hybridgroup.gobot/examples/edison_bme280.go
Thomas Kohler 865e724af0
Build(v2): revert move to v2 subfolder (#932)
* revert move to v2 subfolder
* fix CI and adjust CHANGELOG
2023-05-29 19:23:28 +02:00

61 lines
956 B
Go

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/i2c"
"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
)
func main() {
a := edison.NewAdaptor()
bme280 := i2c.NewBME280Driver(a, i2c.WithAddress(0x76))
work := func() {
gobot.Every(1*time.Second, func() {
t, e := bme280.Temperature()
fmt.Println("Temperature", t)
if e != nil {
fmt.Println(e)
}
p, e := bme280.Pressure()
fmt.Println("Pressure", p)
if e != nil {
fmt.Println(e)
}
a, e := bme280.Altitude()
fmt.Println("Altitude", a)
if e != nil {
fmt.Println(e)
}
h, e := bme280.Humidity()
fmt.Println("Humidity", h)
if e != nil {
fmt.Println(e)
}
})
}
robot := gobot.NewRobot("bme280bot",
[]gobot.Connection{a},
[]gobot.Device{bme280},
work,
)
err := robot.Start()
if err != nil {
fmt.Println(err)
}
}