#include <Math.h>
int gyroPin = A0;             // declare the input pin for the analog gyro

float reference_Value=0;
int sensorValue = 0;            // variable to store the value coming from the analog gyro
double angularVelocity;

void setup() {

   int i;
   float sum=0;
   pinMode(gyroPin, INPUT);
   Serial.begin(9600);
   Serial.println("Please do not rotate it before calibrate!");
   Serial.println("Get the reference value:");
    
   for(i=0;i<1000;i++)
   {
       // read the value from the sensor:
       sensorValue = analogRead(gyroPin);
       sum += sensorValue;
       delay(2);
   }
   reference_Value = sum/1000.0;
   Serial.println(reference_Value);
   Serial.println("Now you can begin your test!");
}

void loop() 
{

   sensorValue = analogRead(gyroPin);
   angularVelocity =((double)(sensorValue-reference_Value)*4930.0)/1023.0/0.67; //get the angular velocity
   Serial.print(angularVelocity);
   Serial.println("deg/s");
   Serial.println(" ");
   delay(1000);
}
