gobot.io/x/gobot@v1.16.0/examples/chip_mpu6050.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"time"
    10  
    11  	"gobot.io/x/gobot"
    12  	"gobot.io/x/gobot/drivers/i2c"
    13  	"gobot.io/x/gobot/platforms/chip"
    14  )
    15  
    16  func main() {
    17  	board := chip.NewAdaptor()
    18  	mpu6050 := i2c.NewMPU6050Driver(board)
    19  
    20  	work := func() {
    21  		gobot.Every(100*time.Millisecond, func() {
    22  			mpu6050.GetData()
    23  
    24  			fmt.Println("Accelerometer", mpu6050.Accelerometer)
    25  			fmt.Println("Gyroscope", mpu6050.Gyroscope)
    26  			fmt.Println("Temperature", mpu6050.Temperature)
    27  		})
    28  	}
    29  
    30  	robot := gobot.NewRobot("mpu6050Bot",
    31  		[]gobot.Connection{board},
    32  		[]gobot.Device{mpu6050},
    33  		work,
    34  	)
    35  
    36  	robot.Start()
    37  }