The output form my gyro will give a reading from -180 to 180 and roll over. I need to add an offset but maintain the rollover
int Baring = 170; int CalBaring; CalBaring= Baring + 100;// adjust for error if(CalBaring > 180) CalBaring= -180 + (CalBaring- 180); // rollover to negative if(CalBaring < -180) CalBaring= 180 - (CalBaring+ 180); // rollover to positive Serial.print(CalBaring)
Is there a simpler way than doing it with all the if statements?
I tried searching for this on google but I’m not sure exactly what to look for.