summaryrefslogtreecommitdiff
path: root/src/gyro.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-12-22 14:48:22 +0100
committerHampusM <hampus@hampusmat.com>2021-12-22 14:48:22 +0100
commitfd57482ffc6621562a8687829a7349301dabb97a (patch)
treeec9ccb8d6b219cef3027b1ab62d8d8b55a4f5290 /src/gyro.cpp
parentfe0e3b8202ee2b96654ee6355d8ed3dad97d9658 (diff)
refactor: replace GY521 library
Diffstat (limited to 'src/gyro.cpp')
-rw-r--r--src/gyro.cpp22
1 files changed, 10 insertions, 12 deletions
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()