examples: add Firmata button metal example
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
e08e8b02ff
commit
91aa54d37b
|
@ -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() {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue