2014-11-10 07:37:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 22:58:43 +08:00
|
|
|
"github.com/hybridgroup/gobot/drivers/i2c"
|
2014-11-10 07:37:12 +08:00
|
|
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
|
|
|
mpu6050 := i2c.NewMPU6050Driver(firmataAdaptor)
|
2014-11-10 07:37:12 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
|
|
|
fmt.Println("Accelerometer", mpu6050.Accelerometer)
|
|
|
|
fmt.Println("Gyroscope", mpu6050.Gyroscope)
|
|
|
|
fmt.Println("Temperature", mpu6050.Temperature)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("mpu6050Bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{mpu6050},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|