docs: modify metal example to range thru channel instead of select

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-01-30 11:48:15 +01:00
parent 96059ef294
commit 66f5b483f1
1 changed files with 14 additions and 10 deletions

View File

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