2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-01-03 05:36:30 +08:00
|
|
|
/*
|
2017-06-10 19:18:29 +08:00
|
|
|
How to setup
|
|
|
|
You must be using a WiFi-connected microcontroller,
|
|
|
|
that has been flashed with the WifiFirmata sketch.
|
|
|
|
You then run the go program on your computer, and communicate
|
|
|
|
wirelessly with the microcontroller.
|
|
|
|
|
|
|
|
How to run
|
|
|
|
Pass the IP address/port as first param:
|
2017-01-03 05:36:30 +08:00
|
|
|
|
2017-01-03 05:37:07 +08:00
|
|
|
go run examples/wifi_firmata_blink.go 192.168.0.39:3030
|
2017-01-03 05:36:30 +08:00
|
|
|
*/
|
|
|
|
|
2017-01-03 04:40:20 +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.NewTCPAdaptor(os.Args[1])
|
2017-01-03 05:02:43 +08:00
|
|
|
led := gpio.NewLedDriver(firmataAdaptor, "2")
|
2017-01-03 04:40:20 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
led.Toggle()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|