gobot.io/x/gobot/v2@v2.1.0/examples/gopigo3_grove_light_sensor.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 package main 8 9 import ( 10 "fmt" 11 12 "gobot.io/x/gobot/v2" 13 "gobot.io/x/gobot/v2/drivers/aio" 14 "gobot.io/x/gobot/v2/platforms/dexter/gopigo3" 15 "gobot.io/x/gobot/v2/platforms/raspi" 16 ) 17 18 func main() { 19 raspiAdaptor := raspi.NewAdaptor() 20 gpg3 := gopigo3.NewDriver(raspiAdaptor) 21 sensor := aio.NewGroveLightSensorDriver(gpg3, "AD_1_1") 22 23 work := func() { 24 sensor.On(sensor.Event("data"), func(data interface{}) { 25 fmt.Println("sensor", data) 26 }) 27 } 28 29 robot := gobot.NewRobot("gopigo3sensor", 30 []gobot.Connection{raspiAdaptor}, 31 []gobot.Device{gpg3, sensor}, 32 work, 33 ) 34 35 robot.Start() 36 }