From faa08454cd8ccc51d740a55dc559d7017172f10a Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 2 Jul 2014 15:44:26 +0200 Subject: [PATCH] Fixed Smoothing example "index" variable name create conflicts with Arduino Due where "index" is a reserved word for Posix C. --- .../examples/03.Analog/Smoothing/Smoothing.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino index cf6935de3..c2a18c320 100644 --- a/build/shared/examples/03.Analog/Smoothing/Smoothing.ino +++ b/build/shared/examples/03.Analog/Smoothing/Smoothing.ino @@ -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;