hybridgroup.gobot/examples/firmata_bmp180.go

41 lines
650 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])
bmp180 := i2c.NewBMP180Driver(firmataAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
t, _ := bmp180.Temperature()
fmt.Println("Temperature", t)
p, _ := bmp180.Pressure()
fmt.Println("Pressure", p)
})
}
robot := gobot.NewRobot("bmp180bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{bmp180},
work,
)
robot.Start()
}