1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
hybridgroup.gobot/examples/chip_button.go
Hrishikesh Tapaswi ed4522248f Name C.H.I.P. pins according to printed names
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>
2016-02-17 12:25:15 -08:00

35 lines
678 B
Go

package main
import (
"fmt"
"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-P0")
work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
fmt.Println("button pressed")
})
gobot.On(button.Event("release"), func(data interface{}) {
fmt.Println("button released")
})
}
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{chipAdaptor},
[]gobot.Device{button},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}