void check_battery_voltage(void) { loop_counter = 0; //Reset the loop counter. battery_voltage = analogRead(battIn); //Set battery voltage. while (data != 'q') { //Stay in this loop until the data variable data holds a q. delayMicroseconds(4000); //Wait for 4000us to simulate a 250Hz loop. if (Serial1.available() > 0) { //If Serial1 data is available. data = Serial1.read(); //Read the incomming byte. delay(100); //Wait for any other bytes to come in. while (Serial1.available() > 0)loop_counter = Serial1.read(); //Empty the Serial1 buffer. } loop_counter++; if (loop_counter == 250) { //Print the battery voltage every second. Serial1.print("Voltage = "); //Print some preliminary information. Serial1.print(battery_voltage / 112.81, 1); //Print the avarage battery voltage to the Serial1 monitor. Serial1.println("V"); //Print some trailing information. loop_counter = 0; //Reset the loop counter. } //A complimentary filter is used to filter out the voltage spikes caused by the ESC's. battery_voltage = (battery_voltage * 0.99) + ((float)analogRead(battIn) * 0.01); } loop_counter = 0; //Reset the loop counter. print_intro(); //Print the intro to the Serial1 monitor. }