1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-19 13:54:23 +01:00

Fixed Smoothing example

"index" variable name create conflicts with Arduino Due where "index" is
a reserved word for Posix C.
This commit is contained in:
Cristian Maglie 2014-07-02 15:44:26 +02:00
parent 494d3de97d
commit faa08454cd

View File

@ -28,7 +28,7 @@
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
@ -45,18 +45,18 @@ void setup()
void loop() {
// subtract the last reading:
total= total - readings[index];
total= total - readings[readIndex];
// read from the sensor:
readings[index] = analogRead(inputPin);
readings[readIndex] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
total= total + readings[readIndex];
// advance to the next position in the array:
index = index + 1;
readIndex = readIndex + 1;
// if we're at the end of the array...
if (index >= numReadings)
if (readIndex >= numReadings)
// ...wrap around to the beginning:
index = 0;
readIndex = 0;
// calculate the average:
average = total / numReadings;