Created
August 22, 2019 19:53
-
-
Save Flati/5e339ec2af7294cd18ad8109e86d2e31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() | |
{ | |
if (digitalRead(CHARGE_PIN) == CHARGE_OFF) | |
{ | |
charging(); | |
} | |
while (Bluefruit.connected()) | |
{ | |
noInterrupts(); | |
//readGyro(); | |
//readAccel(); | |
readBoth(); | |
interrupts(); | |
} | |
} | |
void readGyro() | |
{ | |
Wire.beginTransmission(MPU_ADDRESS); | |
Wire.write(GYRO_XOUT_H); | |
Wire.endTransmission(); | |
Wire.requestFrom(MPU_ADDRESS, 6); | |
angularVelocity[0] = Wire.read()<<8 | Wire.read(); | |
angularVelocity[1] = Wire.read()<<8 | Wire.read(); | |
angularVelocity[2] = Wire.read()<<8 | Wire.read(); | |
} | |
void readAccel() | |
{ | |
Wire.beginTransmission(MPU_ADDRESS); | |
Wire.write(ACCEL_XOUT_H); | |
Wire.endTransmission(); | |
Wire.requestFrom(MPU_ADDRESS, 6); | |
acceleration[0] = Wire.read()<<8 | Wire.read(); | |
acceleration[1] = Wire.read()<<8 | Wire.read(); | |
acceleration[2] = Wire.read()<<8 | Wire.read(); | |
} | |
void readBoth() | |
{ | |
Wire.beginTransmission(MPU_ADDRESS); | |
Wire.write(GYRO_XOUT_H); | |
Wire.write(ACCEL_XOUT_H); | |
Wire.endTransmission(); | |
Wire.requestFrom(MPU_ADDRESS, 12); | |
if (Wire.available() <= 12) | |
{ | |
angularVelocity[0] = Wire.read()<<8 | Wire.read(); | |
angularVelocity[1] = Wire.read()<<8 | Wire.read(); | |
angularVelocity[2] = Wire.read()<<8 | Wire.read(); | |
acceleration[0] = Wire.read()<<8 | Wire.read(); | |
acceleration[1] = Wire.read()<<8 | Wire.read(); | |
acceleration[2] = Wire.read()<<8 | Wire.read(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment