hybridgroup.gobot/examples/firmata_lidarlite.go

35 lines
637 B
Go
Raw Normal View History

2015-03-28 00:55:44 +08:00
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()
}