From fd57482ffc6621562a8687829a7349301dabb97a Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 22 Dec 2021 14:48:22 +0100 Subject: refactor: replace GY521 library --- src/gyro.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/gyro.cpp') diff --git a/src/gyro.cpp b/src/gyro.cpp index 668cef1..1a81850 100644 --- a/src/gyro.cpp +++ b/src/gyro.cpp @@ -1,7 +1,8 @@ #include "Arduino.h" -#include "GY521.h" +#include "Wire.h" +#include "sensor.hpp" -GY521 sensor(0x68); +Sensor sensor(0x68, &Wire); void setup() { @@ -10,26 +11,23 @@ void setup() // Wait for Serial because the Arduino Leonardo is weird while (!Serial) {} - Wire.begin(); - - delay(100); - while (!sensor.wakeup()) + while (!sensor.begin()) { Serial.print(millis()); - Serial.println("Error: Could not connect to the GY521 sensor. Retrying after 2000 milliseconds..."); + Serial.println("Error: Could not connect to the sensor. Retrying after 2000 milliseconds..."); delay(2000); } sensor.setAccelSensitivity(2); // 8g sensor.setGyroSensitivity(1); // 500 degrees/s - sensor.setThrottle(); + sensor.setThrottleEnabled(true); Serial.println("start..."); // Calibration values - sensor.axe = 0.198; - sensor.aye = -0.018; - sensor.gxe = 0.780; - sensor.gye = -1.495; + sensor.accel_cal_x = 0.198; + sensor.accel_cal_y = -0.018; + sensor.gyro_cal_x = 0.780; + sensor.gyro_cal_y = -1.495; } void loop() -- cgit v1.2.3-18-g5258