Skip to content

Instantly share code, notes, and snippets.

@OMikeGray

OMikeGray/readPotentiometer.c Secret

Created Jun 5, 2020
Embed
What would you like to do?
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