2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2014-11-10 07:37:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2014-11-10 07:37:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
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() {
|
2017-02-11 17:37:34 +08:00
|
|
|
mpu6050.GetData()
|
|
|
|
|
2014-11-10 07:37:12 +08:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2014-11-10 07:37:12 +08:00
|
|
|
}
|