Add MMA7660 accelerometer example for C.H.I.P.

This commit is contained in:
deadprogram 2016-02-07 09:08:29 -08:00
parent 6051c0fd8d
commit 08b756f917
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package main
import (
"fmt"
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/i2c"
"github.com/hybridgroup/gobot/platforms/chip"
)
func main() {
gbot := gobot.NewGobot()
board := chip.NewChipAdaptor("chip")
accel := i2c.NewGroveAccelerometerDriver(board, "accel")
work := func() {
gobot.Every(500*time.Millisecond, func() {
if x, y, z, err := accel.XYZ(); err == nil {
fmt.Println(x, y, z)
fmt.Println(accel.Acceleration(x, y, z))
} else {
fmt.Println(err)
}
})
}
robot := gobot.NewRobot("accelBot",
[]gobot.Connection{board},
[]gobot.Device{accel},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}