mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-26 13:48:49 +08:00

It's more convenient to refer to a pin by the name that's printed right on the header itself instead of having to count the pin number. Signed-off-by: Hrishikesh Tapaswi <hrishikesh195@yahoo.com>
34 lines
689 B
Go
34 lines
689 B
Go
package main
|
|
|
|
import (
|
|
"github.com/hybridgroup/gobot"
|
|
"github.com/hybridgroup/gobot/platforms/chip"
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
)
|
|
|
|
func main() {
|
|
gbot := gobot.NewGobot()
|
|
|
|
chipAdaptor := chip.NewChipAdaptor("chip")
|
|
button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P6")
|
|
led := gpio.NewLedDriver(chipAdaptor, "led", "XIO-P7")
|
|
|
|
work := func() {
|
|
gobot.On(button.Event("push"), func(data interface{}) {
|
|
led.On()
|
|
})
|
|
|
|
gobot.On(button.Event("release"), func(data interface{}) {
|
|
led.Off()
|
|
})
|
|
}
|
|
|
|
robot := gobot.NewRobot("buttonBot",
|
|
[]gobot.Connection{chipAdaptor},
|
|
[]gobot.Device{button, led},
|
|
work,
|
|
)
|
|
gbot.AddRobot(robot)
|
|
gbot.Start()
|
|
}
|