gobot.io/x/gobot@v1.16.0/examples/gopigo3_grove_button.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "fmt" 9 10 "gobot.io/x/gobot" 11 "gobot.io/x/gobot/drivers/gpio" 12 "gobot.io/x/gobot/platforms/dexter/gopigo3" 13 "gobot.io/x/gobot/platforms/raspi" 14 ) 15 16 func main() { 17 raspiAdaptor := raspi.NewAdaptor() 18 gpg3 := gopigo3.NewDriver(raspiAdaptor) 19 led := gpio.NewGroveLedDriver(gpg3, "AD_1_1") 20 button := gpio.NewGroveButtonDriver(gpg3, "AD_2_1") 21 22 work := func() { 23 button.On(gpio.ButtonPush, func(data interface{}) { 24 fmt.Println("On!") 25 led.On() 26 }) 27 button.On(gpio.ButtonRelease, func(data interface{}) { 28 fmt.Println("Off!") 29 led.Off() 30 }) 31 } 32 33 robot := gobot.NewRobot("gopigo3button", 34 []gobot.Connection{raspiAdaptor}, 35 []gobot.Device{gpg3, button, led}, 36 work, 37 ) 38 39 robot.Start() 40 }