hybridgroup.gobot/examples/firmata_direct_pin.go

40 lines
664 B
Go

package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
)
func main() {
gbot := gobot.NewGobot()
firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
pin := gpio.NewDirectPinDriver(firmataAdaptor, "pin", "13")
work := func() {
level := byte(1)
gobot.Every(1*time.Second, func() {
pin.DigitalWrite(level)
if level == 1 {
level = 0
} else {
level = 1
}
})
}
robot := gobot.NewRobot("pinBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{pin},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}