Add lidar example
This commit is contained in:
parent
e31c205749
commit
96c0677d36
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue