Add lidar example

This commit is contained in:
Adrian Zankich 2015-03-27 09:55:44 -07:00
parent e31c205749
commit 96c0677d36
1 changed files with 34 additions and 0 deletions

View File

@ -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()
}