gobot.io/x/gobot/v2@v2.1.0/examples/edison_miniboard_grove_accelerometer.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 package main 8 9 import ( 10 "fmt" 11 "time" 12 13 "gobot.io/x/gobot/v2" 14 "gobot.io/x/gobot/v2/drivers/i2c" 15 "gobot.io/x/gobot/v2/platforms/intel-iot/edison" 16 ) 17 18 func main() { 19 board := edison.NewAdaptor("miniboard") 20 21 accel := i2c.NewGroveAccelerometerDriver(board) 22 23 work := func() { 24 gobot.Every(500*time.Millisecond, func() { 25 if x, y, z, err := accel.XYZ(); err == nil { 26 fmt.Println(x, y, z) 27 fmt.Println(accel.Acceleration(x, y, z)) 28 } else { 29 fmt.Println(err) 30 } 31 }) 32 } 33 34 robot := gobot.NewRobot("accelBot", 35 []gobot.Connection{board}, 36 []gobot.Device{accel}, 37 work, 38 ) 39 40 robot.Start() 41 }