1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00
hybridgroup.gobot/examples/firmata_bmp280.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

44 lines
710 B
Go

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"os"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/i2c"
"gobot.io/x/gobot/v2/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
bmp280 := i2c.NewBMP280Driver(firmataAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
t, _ := bmp280.Temperature()
fmt.Println("Temperature", t)
p, _ := bmp280.Pressure()
fmt.Println("Pressure", p)
a, _ := bmp280.Altitude()
fmt.Println("Altitude", a)
})
}
robot := gobot.NewRobot("bmp280bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{bmp280},
work,
)
robot.Start()
}