1
0
mirror of https://github.com/kidoman/embd synced 2024-11-12 20:48:55 +01:00
embd/samples/l3gd20.go

37 lines
530 B
Go
Raw Normal View History

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
dt := 0.1 // Seconds
2014-01-02 02:20:57 +01:00
for {
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
log.Printf("%v", z)
2014-01-02 02:20:57 +01:00
time.Sleep(time.Duration(dt*1000) * time.Millisecond)
}
}