Skip to content

Instantly share code, notes, and snippets.

@anoldguy
Last active January 12, 2016 02:24
Show Gist options
  • Select an option

  • Save anoldguy/539e0042e9673ecfaa68 to your computer and use it in GitHub Desktop.

Select an option

Save anoldguy/539e0042e9673ecfaa68 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/raspi"
"github.com/hybridgroup/gobot/api"
"log"
)
func main() {
gbot := gobot.NewGobot()
r := raspi.NewRaspiAdaptor("raspi")
led := gpio.NewLedDriver(r, "led", "37")
button := gpio.NewButtonDriver(r, "button", "12")
api.NewAPI(gbot).Start()
work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
led.On()
log.Println("Button Pushed")
})
gobot.On(button.Event("release"), func(data interface{}) {
led.Off()
log.Println("Button Released")
})
}
robot := gbot.AddRobot(gobot.NewRobot("blinkBot",
[]gobot.Connection{r},
[]gobot.Device{led, button},
work,
))
// http://192.168.1.204:3000/api/robots/blinkBot/commands/led_on
robot.AddCommand("led_on", func(params map[string]interface{}) interface {} {
led.On()
return "LED ON!"
})
// http://192.168.1.204:3000/api/robots/blinkBot/commands/led_off
robot.AddCommand("led_off", func(params map[string]interface{}) interface {} {
led.Off()
return "LED OFF!"
})
gbot.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment