hybridgroup.gobot/examples/firmata_lidarlite.go

45 lines
720 B
Go
Raw Normal View History

//go:build example
// +build example
//
// Do not build by default.
/*
How to run
Pass serial port to use as the first param:
go run examples/firmata_lidarlite.go /dev/ttyACM0
*/
2015-03-28 00:55:44 +08:00
package main
import (
"fmt"
"os"
2015-03-28 00:55:44 +08:00
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/i2c"
"gobot.io/x/gobot/v2/platforms/firmata"
2015-03-28 00:55:44 +08:00
)
func main() {
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
lidar := i2c.NewLIDARLiteDriver(firmataAdaptor)
2015-03-28 00:55:44 +08:00
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,
)
robot.Start()
2015-03-28 00:55:44 +08:00
}