2015-07-10 02:50:39 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/platforms/intel-iot/edison"
|
2015-07-10 02:50:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
board := edison.NewAdaptor()
|
|
|
|
accel := i2c.NewGroveAccelerometerDriver(board)
|
2015-07-10 02:50:39 +08:00
|
|
|
|
|
|
|
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()
|
2015-07-10 02:50:39 +08:00
|
|
|
}
|