2016-08-30 19:27:50 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
e := edison.NewEdisonAdaptor("edison")
|
|
|
|
led := gpio.NewLedDriver(e, "led", "13")
|
|
|
|
button := gpio.NewButtonDriver(e, "button", "5")
|
|
|
|
|
|
|
|
e.Connect()
|
|
|
|
led.Start()
|
|
|
|
button.Start()
|
|
|
|
|
|
|
|
led.Off()
|
|
|
|
|
|
|
|
buttonEvents := button.Subscribe()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case event := <-buttonEvents:
|
|
|
|
fmt.Println("Event:", event.Name, event.Data)
|
2016-09-01 18:17:43 +08:00
|
|
|
if event.Name == gpio.ButtonPush {
|
2016-08-30 19:27:50 +08:00
|
|
|
led.Toggle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|