2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-01-17 04:45:37 +08:00
|
|
|
/*
|
2017-06-10 19:18:29 +08:00
|
|
|
How to run
|
|
|
|
Pass the BLE address or BLE name as first param:
|
2017-01-17 04:45:37 +08:00
|
|
|
|
|
|
|
go run examples/ble_firmata_blink.go FIRMATA
|
|
|
|
|
2017-06-10 19:18:29 +08:00
|
|
|
NOTE: sudo is required to use BLE in Linux
|
2017-01-17 04:45:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
firmataAdaptor := firmata.NewBLEAdaptor(os.Args[1])
|
|
|
|
led := gpio.NewLedDriver(firmataAdaptor, "13")
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
led.Toggle()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|