gobot.io/x/gobot@v1.16.0/examples/pebble_accelerometer.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "fmt" 9 10 "gobot.io/x/gobot" 11 "gobot.io/x/gobot/api" 12 "gobot.io/x/gobot/platforms/pebble" 13 ) 14 15 func main() { 16 master := gobot.NewMaster() 17 a := api.NewAPI(master) 18 a.Port = "8080" 19 a.Start() 20 21 pebbleAdaptor := pebble.NewAdaptor() 22 pebbleDriver := pebble.NewDriver(pebbleAdaptor) 23 24 work := func() { 25 pebbleDriver.On(pebbleDriver.Event("accel"), func(data interface{}) { 26 fmt.Println(data.(string)) 27 }) 28 } 29 30 robot := gobot.NewRobot("pebble", 31 []gobot.Connection{pebbleAdaptor}, 32 []gobot.Device{pebbleDriver}, 33 work, 34 ) 35 36 master.AddRobot(robot) 37 38 master.Start() 39 }