2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2017-03-13 11:01:39 -04:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2014-05-23 17:09:18 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-10 17:21:21 -07:00
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/api"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/pebble"
|
2014-05-23 17:09:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-18 21:08:25 +02:00
|
|
|
master := gobot.NewMaster()
|
|
|
|
a := api.NewAPI(master)
|
2014-08-01 09:46:07 -07:00
|
|
|
a.Port = "8080"
|
|
|
|
a.Start()
|
2014-05-23 17:09:18 -05:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
pebbleAdaptor := pebble.NewAdaptor()
|
|
|
|
pebbleDriver := pebble.NewDriver(pebbleAdaptor)
|
2014-05-23 17:09:18 -05:00
|
|
|
|
|
|
|
work := func() {
|
2024-02-11 15:34:50 +01:00
|
|
|
_ = pebbleDriver.On(pebbleDriver.Event("accel"), func(data interface{}) {
|
2014-05-23 17:09:18 -05:00
|
|
|
fmt.Println(data.(string))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("pebble",
|
|
|
|
[]gobot.Connection{pebbleAdaptor},
|
|
|
|
[]gobot.Device{pebbleDriver},
|
|
|
|
work,
|
|
|
|
)
|
2014-05-23 17:09:18 -05:00
|
|
|
|
2016-10-18 21:08:25 +02:00
|
|
|
master.AddRobot(robot)
|
2014-07-08 18:36:14 -07:00
|
|
|
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := master.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-05-23 17:09:18 -05:00
|
|
|
}
|