hybridgroup.gobot/examples/firmata_mpl115a2.go

50 lines
831 B
Go
Raw Normal View History

//go:build example
// +build example
//
// Do not build by default.
/*
How to run
Pass serial port to use as the first param:
go run examples/firmata_mpl115a2.go /dev/ttyACM0
*/
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])
mpl115a2 := i2c.NewMPL115A2Driver(firmataAdaptor)
work := func() {
gobot.Every(1*time.Second, func() {
press, _ := mpl115a2.Pressure()
fmt.Println("Pressure", press)
temp, _ := mpl115a2.Temperature()
fmt.Println("Temperature", temp)
})
}
robot := gobot.NewRobot("mpl115a2Bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{mpl115a2},
work,
)
if err := robot.Start(); err != nil {
panic(err)
}
}