diff --git a/examples/firmata_button.go b/examples/firmata_button.go index dce50e9b..88cd2fb1 100644 --- a/examples/firmata_button.go +++ b/examples/firmata_button.go @@ -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() { diff --git a/examples/firmata_metal_button.go b/examples/firmata_metal_button.go new file mode 100644 index 00000000..c011628e --- /dev/null +++ b/examples/firmata_metal_button.go @@ -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() + } + } + } +}