diff --git a/examples/firmata_lidarlite.go b/examples/firmata_lidarlite.go new file mode 100644 index 00000000..79d06605 --- /dev/null +++ b/examples/firmata_lidarlite.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "time" + + "github.com/hybridgroup/gobot" + "github.com/hybridgroup/gobot/platforms/firmata" + "github.com/hybridgroup/gobot/platforms/i2c" +) + +func main() { + gbot := gobot.NewGobot() + + firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") + lidar := i2c.NewLIDARLiteDriver(firmataAdaptor, "lidar") + + work := func() { + gobot.Every(100*time.Millisecond, func() { + distance, _ := lidar.Distance() + fmt.Println("Distance", distance) + }) + } + + robot := gobot.NewRobot("lidarbot", + []gobot.Connection{firmataAdaptor}, + []gobot.Device{lidar}, + work, + ) + + gbot.AddRobot(robot) + + gbot.Start() +}