gobot.io/x/gobot@v1.16.0/examples/edison_miniboard_grove_accelerometer.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/intel-iot/edison"
    14  )
    15  
    16  func main() {
    17  	board := edison.NewAdaptor()
    18  	board.SetBoard("miniboard")
    19  
    20  	accel := i2c.NewGroveAccelerometerDriver(board)
    21  
    22  	work := func() {
    23  		gobot.Every(500*time.Millisecond, func() {
    24  			if x, y, z, err := accel.XYZ(); err == nil {
    25  				fmt.Println(x, y, z)
    26  				fmt.Println(accel.Acceleration(x, y, z))
    27  			} else {
    28  				fmt.Println(err)
    29  			}
    30  		})
    31  	}
    32  
    33  	robot := gobot.NewRobot("accelBot",
    34  		[]gobot.Connection{board},
    35  		[]gobot.Device{accel},
    36  		work,
    37  	)
    38  
    39  	robot.Start()
    40  }