hybridgroup.gobot/examples/metal_button.go

32 lines
513 B
Go

package main
import (
"fmt"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)
func main() {
e := edison.NewAdaptor()
led := gpio.NewLedDriver(e, "13")
button := gpio.NewButtonDriver(e, "5")
e.Connect()
led.Start()
button.Start()
led.Off()
buttonEvents := button.Subscribe()
for {
select {
case event := <-buttonEvents:
fmt.Println("Event:", event.Name, event.Data)
if event.Name == gpio.ButtonPush {
led.Toggle()
}
}
}
}