2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-03-28 21:51:37 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-03-28 21:51:37 +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:51:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
|
2017-03-28 23:54:19 +08:00
|
|
|
bme280 := i2c.NewBME280Driver(firmataAdaptor)
|
2017-03-28 21:51:37 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
t, _ := bme280.Temperature()
|
|
|
|
fmt.Println("Temperature", t)
|
2017-03-28 23:34:04 +08:00
|
|
|
|
|
|
|
p, _ := bme280.Pressure()
|
|
|
|
fmt.Println("Pressure", p)
|
2017-03-28 23:35:27 +08:00
|
|
|
|
2017-04-01 16:29:57 +08:00
|
|
|
a, _ := bme280.Altitude()
|
|
|
|
fmt.Println("Altitude", a)
|
|
|
|
|
2017-03-28 23:35:27 +08:00
|
|
|
h, _ := bme280.Humidity()
|
|
|
|
fmt.Println("Humidity", h)
|
2017-03-28 21:51:37 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bme280bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{bme280},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|