2016-10-19 00:47:26 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2016-10-19 00:47:26 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|