44 lines
714 B
Go
44 lines
714 B
Go
//go:build example
|
|
// +build example
|
|
|
|
//
|
|
// Do not build by default.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"gobot.io/x/gobot/v2"
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
|
|
)
|
|
|
|
func main() {
|
|
board := edison.NewAdaptor("miniboard")
|
|
|
|
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,
|
|
)
|
|
|
|
if err := robot.Start(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|