hybridgroup.gobot/examples/gopigo3_grove_light_sensor.go

40 lines
754 B
Go
Raw Permalink 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,
)
if err := robot.Start(); err != nil {
panic(err)
}
}