1.2K
Sampling sata is particularly useful for analog sensors such as an LDR or a thermistor
You can change the amount of samples to take and the interval which is in millioseconds
[codesyntax lang=”cpp”]
int sampleData(int analogPin, int samples = 10, int sampleInterval = 100) { 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); }
[/codesyntax]