File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
build/shared/examples/03.Analog/Smoothing Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 2828const int numReadings = 10 ;
2929
3030int 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
3232int total = 0 ; // the running total
3333int average = 0 ; // the average
3434
@@ -45,18 +45,18 @@ void setup()
4545
4646void 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;
You can’t perform that action at this time.
0 commit comments