Skip to content

Instantly share code, notes, and snippets.

@oifland
Created February 10, 2017 02:45
Show Gist options
  • Save oifland/ba1dcedec57e8bd7ac97c70d34a50a8e to your computer and use it in GitHub Desktop.
Save oifland/ba1dcedec57e8bd7ac97c70d34a50a8e to your computer and use it in GitHub Desktop.
Gobot Robot
package main
import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/audio"
"gobot.io/x/gobot/platforms/chip"
)
func main() {
chipAdaptor := chip.NewAdaptor()
button := gpio.NewButtonDriver(chipAdaptor, "XIO-P7")
e := audio.NewAdaptor()
beep := audio.NewDriver(e, "beep.mp3")
work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("over")
})
button.On(gpio.ButtonRelease, func(data interface{}) {
beep.Play()
})
}
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{chipAdaptor, e},
[]gobot.Device{button, beep},
work,
)
robot.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment