examples: add Firmata button metal example

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-10-18 18:47:26 +02:00
parent e08e8b02ff
commit 91aa54d37b
2 changed files with 32 additions and 1 deletions

View File

@ -11,7 +11,7 @@ func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
button := gpio.NewButtonDriver(firmataAdaptor, "2")
button := gpio.NewButtonDriver(firmataAdaptor, "5")
led := gpio.NewLedDriver(firmataAdaptor, "13")
work := func() {

View File

@ -0,0 +1,31 @@
package main
import (
"fmt"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/firmata"
)
func main() {
f := firmata.NewAdaptor("/dev/ttyACM0")
f.Connect()
led := gpio.NewLedDriver(f, "13")
led.Start()
led.Off()
button := gpio.NewButtonDriver(f, "5")
button.Start()
buttonEvents := button.Subscribe()
for {
select {
case event := <-buttonEvents:
fmt.Println("Event:", event.Name, event.Data)
if event.Name == gpio.ButtonPush {
led.Toggle()
}
}
}
}