2014-01-02 02:20:57 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/kid0m4n/go-rpi/i2c"
|
|
|
|
"github.com/kid0m4n/go-rpi/sensor/l3gd20"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bus, err := i2c.NewBus(1)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
gyro := l3gd20.New(bus, l3gd20.R250DPS)
|
|
|
|
defer gyro.Close()
|
|
|
|
|
|
|
|
x, y, z := 0.0, 0.0, 0.0
|
2014-01-07 16:23:41 +01:00
|
|
|
dt := 0.1 // Seconds
|
2014-01-02 02:20:57 +01:00
|
|
|
|
|
|
|
for {
|
2014-01-07 16:23:41 +01:00
|
|
|
dx, dy, dz, err := gyro.OrientationDelta()
|
2014-01-02 02:20:57 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
x += dx * dt
|
|
|
|
y += dy * dt
|
|
|
|
z += dz * dt
|
|
|
|
|
2014-01-07 16:23:41 +01:00
|
|
|
log.Printf("%v", z)
|
2014-01-02 02:20:57 +01:00
|
|
|
|
|
|
|
time.Sleep(time.Duration(dt*1000) * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|