2016-10-07 19:23:17 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/drivers/i2c"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-16 02:02:54 +08:00
|
|
|
gbot := gobot.NewMaster()
|
2016-10-07 19:23:17 +08:00
|
|
|
|
|
|
|
board := edison.NewAdaptor()
|
|
|
|
board.SetBoard("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,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|