From c3c55b2dc80af6e603d5b49e4ea4ce598c1539f6 Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Wed, 24 May 2017 20:08:08 +0300 Subject: [PATCH] better example for all values Signed-off-by: Krasi Georgiev --- samples/mpu6050.go | 11 +++++++++-- sensor/mpu6050/mpu6050.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/samples/mpu6050.go b/samples/mpu6050.go index 866a0d1..5206bec 100644 --- a/samples/mpu6050.go +++ b/samples/mpu6050.go @@ -25,7 +25,8 @@ func main() { bus := embd.NewI2CBus(1) - sensor, _ := mpu6050.New(bus, &mpu6050.Config{GiroScale: "1000", Dlpf: "6"}) + sensor, _ := mpu6050.New(bus, &mpu6050.Config{GiroScale: "1000", AccelScale: "4g", Dlpf: "6"}) + // GiroScale, Dlpf, AccelScale can be omited to use the defaults sensor.Start() defer sensor.Close() @@ -35,13 +36,19 @@ func main() { signal.Notify(stop, os.Interrupt, os.Kill) for { + reading := sensor.Read() + o := reading.Orientation() + v := reading.Velocity() + t := reading.Temperature() + select { case <-stop: return default: - v := sensor.Read().Orientation() print("\033[H\033[2J") // clear the screen for every read + fmt.Println(o) fmt.Println(v) + fmt.Println(t) time.Sleep(200 * time.Millisecond) } } diff --git a/sensor/mpu6050/mpu6050.go b/sensor/mpu6050/mpu6050.go index 14da257..5cd566e 100644 --- a/sensor/mpu6050/mpu6050.go +++ b/sensor/mpu6050/mpu6050.go @@ -86,7 +86,7 @@ func (r *MPU6050Reading) Velocity() velocity { return r.gReading } -func (r *MPU6050Reading) Temp() temperature { +func (r *MPU6050Reading) Temperature() temperature { return r.tReading }