Skip to content

Commit

Permalink
Visualize101.ino: use CurieIMU.*DataReady() methods
Browse files Browse the repository at this point in the history
CurieIMU API has recently gained functions to check if new gyro/accel
data is ready, which means this example no longer needs to keep track of
timing.
  • Loading branch information
eriknyquist committed Oct 11, 2016
1 parent 70fd2c9 commit f2c133e
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions examples/Visualize101/Visualize101.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <MadgwickAHRS.h>

Madgwick filter;
unsigned long microsPerReading, microsPrevious;
float accelScale, gyroScale;

void setup() {
Expand All @@ -18,10 +17,6 @@ void setup() {
CurieIMU.setAccelerometerRange(2);
// Set the gyroscope range to 250 degrees/second
CurieIMU.setGyroRange(250);

// initialize variables to pace updates to correct rate
microsPerReading = 1000000 / 25;
microsPrevious = micros();
}

void loop() {
Expand All @@ -30,11 +25,9 @@ void loop() {
float ax, ay, az;
float gx, gy, gz;
float roll, pitch, heading;
unsigned long microsNow;

// check if it's time to read data and update the filter
microsNow = micros();
if (microsNow - microsPrevious >= microsPerReading) {
// Check if new data is available from gyroscope or accelerometer
if (CurieIMU.gyroDataReady() && CurieIMU.accelDataReady()) {

// read raw data from CurieIMU
CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz);
Expand All @@ -60,9 +53,6 @@ void loop() {
Serial.print(pitch);
Serial.print(" ");
Serial.println(roll);

// increment previous time, so we keep proper pace
microsPrevious = microsPrevious + microsPerReading;
}
}

Expand Down

0 comments on commit f2c133e

Please sign in to comment.