diff --git a/examples/firmata_metal_button.go b/examples/firmata_metal_button.go index 1e706491..baa9aecd 100644 --- a/examples/firmata_metal_button.go +++ b/examples/firmata_metal_button.go @@ -1,31 +1,35 @@ +// TO RUN: +// firmata_metal_button +// +// EXAMPLE: +// go run ./examples/firmata_metal_button /dev/ttyACM0 +// package main import ( "fmt" + "os" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/firmata" ) func main() { - f := firmata.NewAdaptor("/dev/ttyACM0") + f := firmata.NewAdaptor(os.Args[1]) f.Connect() - led := gpio.NewLedDriver(f, "13") + led := gpio.NewLedDriver(f, "2") led.Start() led.Off() - button := gpio.NewButtonDriver(f, "5") + button := gpio.NewButtonDriver(f, "3") button.Start() buttonEvents := button.Subscribe() - for { - select { - case event := <-buttonEvents: - fmt.Println("Event:", event.Name, event.Data) - if event.Name == gpio.ButtonPush { - led.Toggle() - } + for event := range buttonEvents { + fmt.Println("Event:", event.Name, event.Data) + if event.Name == gpio.ButtonPush { + led.Toggle() } } }