2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2016-02-17 09:55:07 +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/chip"
|
2016-02-17 09:55:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
board := chip.NewAdaptor()
|
|
|
|
mpu6050 := i2c.NewMPU6050Driver(board)
|
2016-02-17 09:55:07 +08:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
2017-02-11 17:37:34 +08:00
|
|
|
mpu6050.GetData()
|
|
|
|
|
2016-02-17 09:55:07 +08:00
|
|
|
fmt.Println("Accelerometer", mpu6050.Accelerometer)
|
|
|
|
fmt.Println("Gyroscope", mpu6050.Gyroscope)
|
|
|
|
fmt.Println("Temperature", mpu6050.Temperature)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("mpu6050Bot",
|
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{mpu6050},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
robot.Start()
|
2016-02-17 09:55:07 +08:00
|
|
|
}
|