2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-03-13 23:01:39 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2016-10-07 19:23:17 +08:00
|
|
|
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/intel-iot/edison"
|
2016-10-07 19:23:17 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-12-09 02:29:51 +08:00
|
|
|
board := edison.NewAdaptor("miniboard")
|
2016-10-07 19:23:17 +08:00
|
|
|
|
|
|
|
accel := i2c.NewGroveAccelerometerDriver(board)
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(500*time.Millisecond, func() {
|
|
|
|
if x, y, z, err := accel.XYZ(); err == nil {
|
|
|
|
fmt.Println(x, y, z)
|
|
|
|
fmt.Println(accel.Acceleration(x, y, z))
|
|
|
|
} else {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("accelBot",
|
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{accel},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2016-10-07 19:23:17 +08:00
|
|
|
}
|