]> git.piffa.net Git - arduino/blob - books/ArduinoNextSteps-master/ArduinoNextSteps/sketch_13_02_simple_smoothing/sketch_13_02_simple_smoothing.ino
first commit
[arduino] / books / ArduinoNextSteps-master / ArduinoNextSteps / sketch_13_02_simple_smoothing / sketch_13_02_simple_smoothing.ino
1 // sketch_13_02_simple_smoothing
2 const int samplePin = A1;
3 const float alpha = 0.9;
4
5 void setup()
6 {
7   Serial.begin(9600);
8 }
9
10 void loop()
11 {
12   static float smoothedValue = 0.0;
13   float newReading = (float)analogRead(samplePin);
14   smoothedValue = (alpha * smoothedValue) + ((1 - alpha) * newReading);
15   Serial.print(newReading); Serial.print(",");
16   Serial.println(smoothedValue);
17   delay(1000);
18 }
19