File tree 1 file changed +7
-7
lines changed
build/shared/examples/03.Analog/Smoothing
1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 28
28
const int numReadings = 10 ;
29
29
30
30
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
32
32
int total = 0 ; // the running total
33
33
int average = 0 ; // the average
34
34
@@ -45,18 +45,18 @@ void setup()
45
45
46
46
void loop () {
47
47
// subtract the last reading:
48
- total= total - readings[index ];
48
+ total= total - readings[readIndex ];
49
49
// read from the sensor:
50
- readings[index ] = analogRead (inputPin);
50
+ readings[readIndex ] = analogRead (inputPin);
51
51
// add the reading to the total:
52
- total= total + readings[index ];
52
+ total= total + readings[readIndex ];
53
53
// advance to the next position in the array:
54
- index = index + 1 ;
54
+ readIndex = readIndex + 1 ;
55
55
56
56
// if we're at the end of the array...
57
- if (index >= numReadings)
57
+ if (readIndex >= numReadings)
58
58
// ...wrap around to the beginning:
59
- index = 0 ;
59
+ readIndex = 0 ;
60
60
61
61
// calculate the average:
62
62
average = total / numReadings;
You can’t perform that action at this time.
0 commit comments