2017-03-20 19:31:23 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-03-01 08:23:50 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/platforms/ble"
|
|
|
|
"gobot.io/x/gobot/platforms/microbit"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
|
|
|
|
ubit := microbit.NewAccelerometerDriver(bleAdaptor)
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
ubit.On(microbit.Accelerometer, func(data interface{}) {
|
|
|
|
fmt.Println("Accelerometer", data)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
|
|
[]gobot.Connection{bleAdaptor},
|
|
|
|
[]gobot.Device{ubit},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|