35 lines
637 B
Go
35 lines
637 B
Go
|
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()
|
||
|
}
|