gobot.io/x/gobot@v1.16.0/examples/firmata_metal_button.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 // TO RUN: 6 // firmata_metal_button <PORT> 7 // 8 // EXAMPLE: 9 // go run ./examples/firmata_metal_button /dev/ttyACM0 10 // 11 package main 12 13 import ( 14 "fmt" 15 "os" 16 17 "gobot.io/x/gobot/drivers/gpio" 18 "gobot.io/x/gobot/platforms/firmata" 19 ) 20 21 func main() { 22 f := firmata.NewAdaptor(os.Args[1]) 23 f.Connect() 24 25 led := gpio.NewLedDriver(f, "2") 26 led.Start() 27 led.Off() 28 29 button := gpio.NewButtonDriver(f, "3") 30 button.Start() 31 32 buttonEvents := button.Subscribe() 33 for event := range buttonEvents { 34 fmt.Println("Event:", event.Name, event.Data) 35 if event.Name == gpio.ButtonPush { 36 led.Toggle() 37 } 38 } 39 }