1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Merge branch 'master' into HEAD

Conflicts:
	build/shared/examples/03.Analog/Smoothing/Smoothing.ino
This commit is contained in:
Cristian Maglie 2014-07-02 16:05:23 +02:00
commit 1a7a921f14

View File

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