gobot.io/x/gobot@v1.16.0/examples/gopigo3_grove_light_sensor.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/aio"
    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  	sensor := aio.NewGroveLightSensorDriver(gpg3, "AD_1_1")
    20  
    21  	work := func() {
    22  		sensor.On(sensor.Event("data"), func(data interface{}) {
    23  			fmt.Println("sensor", data)
    24  		})
    25  	}
    26  
    27  	robot := gobot.NewRobot("gopigo3sensor",
    28  		[]gobot.Connection{raspiAdaptor},
    29  		[]gobot.Device{gpg3, sensor},
    30  		work,
    31  	)
    32  
    33  	robot.Start()
    34  }