Skip to content

Instantly share code, notes, and snippets.

@Marzogh
Last active May 23, 2016 23:24
Show Gist options
  • Save Marzogh/091b1fc17c6f5904d8d3fab6c0e70f43 to your computer and use it in GitHub Desktop.
Save Marzogh/091b1fc17c6f5904d8d3fab6c0e70f43 to your computer and use it in GitHub Desktop.
Function to smooth out values from analog sensors
int sampleData(int analogPin, int samples = 8, int sampleInterval = 50) {
int sampleData[samples];
int val = 0;
for (int i = 0; i<samples; i++) {
sampleData[i] = analogRead(analogPin);
val = val + sampleData[i];
delay(sampleInterval);
}
val = (val / samples);
return map(val, 550, 1023, 100, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment