Last active
May 23, 2016 23:24
-
-
Save Marzogh/091b1fc17c6f5904d8d3fab6c0e70f43 to your computer and use it in GitHub Desktop.
Function to smooth out values from analog sensors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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