1
0
mirror of https://github.com/kidoman/embd synced 2024-12-23 05:10:05 +01:00
embd/samples/l3gd20.go

53 lines
791 B
Go
Raw Normal View History

2014-03-02 12:36:34 +05:30
// +build ignore
2014-01-02 06:50:57 +05:30
package main
import (
"flag"
"fmt"
"os"
"os/signal"
2014-01-09 05:26:21 +05:30
"time"
2014-03-03 00:51:23 +05:30
"github.com/kidoman/embd"
2014-02-10 05:05:41 +05:30
"github.com/kidoman/embd/sensor/l3gd20"
_ "github.com/kidoman/embd/host/all"
2014-01-02 06:50:57 +05:30
)
func main() {
flag.Parse()
2014-03-03 00:51:23 +05:30
if err := embd.InitI2C(); err != nil {
panic(err)
}
2014-03-03 00:51:23 +05:30
defer embd.CloseI2C()
2014-03-03 00:51:23 +05:30
bus := embd.NewI2CBus(1)
2014-01-02 06:50:57 +05:30
gyro := l3gd20.New(bus, l3gd20.R250DPS)
defer gyro.Close()
gyro.Start()
2014-01-02 06:50:57 +05:30
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, os.Kill)
2014-01-02 06:50:57 +05:30
orientations, err := gyro.Orientations()
if err != nil {
panic(err)
}
2014-01-02 06:50:57 +05:30
2014-01-09 05:26:21 +05:30
timer := time.Tick(250 * time.Millisecond)
for {
select {
2014-01-09 05:26:21 +05:30
case <-timer:
orientation := <-orientations
fmt.Printf("x: %v, y: %v, z: %v\n", orientation.X, orientation.Y, orientation.Z)
case <-quit:
return
}
2014-01-02 06:50:57 +05:30
}
}