hybridgroup.gobot/examples/raspi_button.go

40 lines
647 B
Go
Raw Normal View History

// +build example
//
// Do not build by default.
2014-11-05 09:14:36 +08:00
package main
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/raspi"
2014-11-05 09:14:36 +08:00
)
func main() {
r := raspi.NewAdaptor()
button := gpio.NewButtonDriver(r, "11")
led := gpio.NewLedDriver(r, "7")
2014-11-05 09:14:36 +08:00
work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
2014-11-05 09:14:36 +08:00
fmt.Println("button pressed")
led.On()
})
button.On(gpio.ButtonRelease, func(data interface{}) {
2014-11-05 09:14:36 +08:00
fmt.Println("button released")
led.Off()
})
}
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{r},
[]gobot.Device{button, led},
work,
)
robot.Start()
2014-11-05 09:14:36 +08:00
}