hybridgroup.gobot/examples/gopigo3_grove_light_sensor.go

38 lines
710 B
Go
Raw Normal View History

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/aio"
"gobot.io/x/gobot/v2/platforms/dexter/gopigo3"
"gobot.io/x/gobot/v2/platforms/raspi"
)
func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
sensor := aio.NewGroveLightSensorDriver(gpg3, "AD_1_1", aio.WithSensorCyclicRead(500*time.Millisecond))
work := func() {
sensor.On(sensor.Event("data"), func(data interface{}) {
fmt.Println("sensor", data)
})
}
robot := gobot.NewRobot("gopigo3sensor",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3, sensor},
work,
)
robot.Start()
}