Skip to content

Instantly share code, notes, and snippets.

@OMikeGray
Created June 5, 2020 02:32
Show Gist options
  • Save OMikeGray/b13f156c080a100a89e5bbd541d0565e to your computer and use it in GitHub Desktop.
Save OMikeGray/b13f156c080a100a89e5bbd541d0565e to your computer and use it in GitHub Desktop.
float readPotentiometer(void){
int sum = 0; // Sum of Measurements
static int j = 0;
valuesToAverage[j] = analogRead(A1); // Place Measurement in Buffer with Previous Values
for(int i = 0; i < numMeasure; i++){
sum +=valuesToAverage[i]; // Add Up all Muasurements
}
if(j < numMeasure-1){j++;}
else{j = 0;}
return conNum*((sum/numMeasure) - 44); // Divide by number of measurements
} // & Convert to Inches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment