Commits

Jody McAdams committed 62d87d8

Now displays the current angle for the X, Y, and Z axis

Comments (0)

Files changed (1)

Sensors/Gyro/Gyro.ino

 float spamTimer = -1.0f;
 float spamInterval = 0.125f; //seconds
 
+float angleX = 0.0f;
+float angleY = 0.0f;
+float angleZ = 0.0f;
+
+
+//If the angle goes beyond 360, wrap it around
+float WrapAngle(float angle)
+{
+  static const float maxAngle = 360.0f;
+  
+  float finalAngle;
+  if(angle > maxAngle)
+  {
+    return angle - maxAngle;
+  }
+  else if(angle < -maxAngle)
+  {
+    return angle + maxAngle;
+  }
+  else
+  {
+    return angle;
+  }
+}
+
 //Program loop
 void loop()
 {
   
   getGyroValues();  // This will update x, y, and z with new values
   
+  angleX += x*timeElapsed;
+  angleY += y*timeElapsed;
+  angleZ += z*timeElapsed;
+  
+  angleX = WrapAngle(angleX);
+  angleY = WrapAngle(angleY);
+  angleZ = WrapAngle(angleZ);
+  
   spamTimer -= timeElapsed;
   if(spamTimer < 0.0f)
   {
     spamTimer = spamInterval;
     
     Serial.print("X:");
-    Serial.print(x);
+    Serial.print(angleX);
     Serial.print(", ");
  
     Serial.print("Y:");
-    Serial.print(y);
+    Serial.print(angleY);
     Serial.print(", ");
 
     Serial.print("Z:");
-    Serial.println(z);
+    Serial.println(angleZ);
   }
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.