2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-07-12 18:08:46 -06:00
|
|
|
/*
|
|
|
|
How to run
|
|
|
|
Pass serial port to use as the first param:
|
|
|
|
|
|
|
|
go run examples/firmata_direct_pin.go /dev/ttyACM0
|
|
|
|
*/
|
|
|
|
|
2014-06-11 11:44:10 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-12 18:08:46 -06:00
|
|
|
"os"
|
2014-07-10 17:21:21 -07:00
|
|
|
"time"
|
|
|
|
|
2016-12-08 13:24:03 +01:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2014-06-11 11:44:10 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-07-12 18:08:46 -06:00
|
|
|
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
|
2016-10-03 16:58:43 +02:00
|
|
|
pin := gpio.NewDirectPinDriver(firmataAdaptor, "13")
|
2014-07-08 18:36:14 -07:00
|
|
|
|
2014-06-11 11:44:10 -07:00
|
|
|
work := func() {
|
|
|
|
level := byte(1)
|
|
|
|
|
|
|
|
gobot.Every(1*time.Second, func() {
|
|
|
|
pin.DigitalWrite(level)
|
|
|
|
if level == 1 {
|
|
|
|
level = 0
|
|
|
|
} else {
|
|
|
|
level = 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-07-08 18:36:14 -07:00
|
|
|
|
|
|
|
robot := gobot.NewRobot("pinBot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{pin},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-18 21:08:25 +02:00
|
|
|
robot.Start()
|
2014-06-11 11:44:10 -07:00
|
|
|
}
|