2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-03-28 21:03:08 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-03-28 21:03:08 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/firmata"
|
2017-03-28 21:03:08 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2017-04-04 22:00:01 +08:00
|
|
|
|
|
|
|
p, _ := bmp180.Pressure()
|
|
|
|
fmt.Println("Pressure", p)
|
2017-03-28 21:03:08 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bmp180bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{bmp180},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|