1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/examples/pebble_accelerometer.go

44 lines
711 B
Go
Raw Normal View History

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
2014-07-10 17:21:21 -07:00
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/platforms/pebble"
)
func main() {
master := gobot.NewMaster()
a := api.NewAPI(master)
a.Port = "8080"
a.Start()
pebbleAdaptor := pebble.NewAdaptor()
pebbleDriver := pebble.NewDriver(pebbleAdaptor)
work := func() {
_ = pebbleDriver.On(pebbleDriver.Event("accel"), func(data interface{}) {
fmt.Println(data.(string))
})
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot("pebble",
[]gobot.Connection{pebbleAdaptor},
[]gobot.Device{pebbleDriver},
work,
)
master.AddRobot(robot)
2014-07-08 18:36:14 -07:00
if err := master.Start(); err != nil {
panic(err)
}
}