Created
February 10, 2017 02:45
-
-
Save oifland/ba1dcedec57e8bd7ac97c70d34a50a8e to your computer and use it in GitHub Desktop.
Gobot Robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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