2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2018-08-25 03:00:51 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2018-08-25 03:00:51 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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/digispark"
|
2018-08-25 03:00:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
board := digispark.NewAdaptor()
|
|
|
|
mpl115a2 := i2c.NewMPL115A2Driver(board)
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
press, _ := mpl115a2.Pressure()
|
|
|
|
fmt.Println("Pressure", press)
|
|
|
|
|
|
|
|
temp, _ := mpl115a2.Temperature()
|
|
|
|
fmt.Println("Temperature", temp)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-21 01:35:55 +08:00
|
|
|
robot := gobot.NewRobot("mpl115Bot",
|
2018-08-25 03:00:51 +08:00
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{mpl115a2},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
2018-08-25 03:00:51 +08:00
|
|
|
}
|
|
|
|
}
|