Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit faa0845

Browse files
committed
Fixed Smoothing example
"index" variable name create conflicts with Arduino Due where "index" is a reserved word for Posix C.
1 parent 494d3de commit faa0845

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎build/shared/examples/03.Analog/Smoothing/Smoothing.ino‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
const int numReadings = 10;
2929

3030
int readings[numReadings]; // the readings from the analog input
31-
int index = 0; // the index of the current reading
31+
int readIndex = 0; // the index of the current reading
3232
int total = 0; // the running total
3333
int average = 0; // the average
3434

@@ -45,18 +45,18 @@ void setup()
4545

4646
void loop() {
4747
// subtract the last reading:
48-
total= total - readings[index];
48+
total= total - readings[readIndex];
4949
// read from the sensor:
50-
readings[index] = analogRead(inputPin);
50+
readings[readIndex] = analogRead(inputPin);
5151
// add the reading to the total:
52-
total= total + readings[index];
52+
total= total + readings[readIndex];
5353
// advance to the next position in the array:
54-
index = index + 1;
54+
readIndex = readIndex + 1;
5555

5656
// if we're at the end of the array...
57-
if (index >= numReadings)
57+
if (readIndex >= numReadings)
5858
// ...wrap around to the beginning:
59-
index = 0;
59+
readIndex = 0;
6060

6161
// calculate the average:
6262
average = total / numReadings;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /