hybridgroup.gobot/examples/firmata_lidarlite.go

35 lines
609 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/drivers/i2c"
2015-03-28 00:55:44 +08:00
"github.com/hybridgroup/gobot/platforms/firmata"
)
func main() {
gbot := gobot.NewMaster()
2015-03-28 00:55:44 +08:00
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
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,
)
gbot.AddRobot(robot)
gbot.Start()
}