1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00
embd/samples/l3gd20.go
2014-01-02 06:50:57 +05:30

44 lines
662 B
Go

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.02
for {
dx, dy, dz, err := gyro.Orientation()
if err != nil {
log.Panic(err)
}
x += dx * dt
y += dy * dt
z += dz * dt
log.Printf("Orientation is (%v, %v, %v)", x, y, z)
temp, err := gyro.Temperature()
if err != nil {
log.Panic(err)
}
log.Printf("Temperature is %v", temp)
time.Sleep(time.Duration(dt*1000) * time.Millisecond)
}
}