Skip to content

Instantly share code, notes, and snippets.

@AkshayPathak
Created May 5, 2016 01:26
Show Gist options
  • Save AkshayPathak/83d2fba8a1699c9398ab66cded6dca8d to your computer and use it in GitHub Desktop.
Save AkshayPathak/83d2fba8a1699c9398ab66cded6dca8d to your computer and use it in GitHub Desktop.
Converting raw gyroscope inputs to an angle.
unsigned char gyroValue = 0;
unsigned char offset = 136;
float angle = 0;
float gyroRate;
void setup() {
Serial.begin(9600);
}
void loop() {
gyroValue = analogRead(A0) >> 2; // Work with 8 most significant bits!
gyroRate = (gyroValue - offset) * 5.5; // Sensitivity has been found trial/error
angle += gyroRate / 100.0;
Serial.print(angle);
Serial.print("\n");
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment