mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@ -3,9 +3,9 @@
|
||||
Smoothing
|
||||
|
||||
Reads repeatedly from an analog input, calculating a running average
|
||||
and printing it to the computer. Keeps ten readings in an array and
|
||||
and printing it to the computer. Keeps ten readings in an array and
|
||||
continually averages them.
|
||||
|
||||
|
||||
The circuit:
|
||||
* Analog sensor (potentiometer will do) attached to analog input 0
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
http://www.arduino.cc/en/Tutorial/Smoothing
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
@ -37,32 +37,32 @@ int inputPin = A0;
|
||||
void setup()
|
||||
{
|
||||
// initialize serial communication with computer:
|
||||
Serial.begin(9600);
|
||||
// initialize all the readings to 0:
|
||||
Serial.begin(9600);
|
||||
// initialize all the readings to 0:
|
||||
for (int thisReading = 0; thisReading < numReadings; thisReading++)
|
||||
readings[thisReading] = 0;
|
||||
readings[thisReading] = 0;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// subtract the last reading:
|
||||
total= total - readings[index];
|
||||
// read from the sensor:
|
||||
readings[index] = analogRead(inputPin);
|
||||
total = total - readings[index];
|
||||
// read from the sensor:
|
||||
readings[index] = analogRead(inputPin);
|
||||
// add the reading to the total:
|
||||
total= total + readings[index];
|
||||
// advance to the next position in the array:
|
||||
index = index + 1;
|
||||
total = total + readings[index];
|
||||
// advance to the next position in the array:
|
||||
index = index + 1;
|
||||
|
||||
// if we're at the end of the array...
|
||||
if (index >= numReadings)
|
||||
// ...wrap around to the beginning:
|
||||
index = 0;
|
||||
if (index >= numReadings)
|
||||
// ...wrap around to the beginning:
|
||||
index = 0;
|
||||
|
||||
// calculate the average:
|
||||
average = total / numReadings;
|
||||
average = total / numReadings;
|
||||
// send it to the computer as ASCII digits
|
||||
Serial.println(average);
|
||||
delay(1); // delay in between reads for stability
|
||||
Serial.println(average);
|
||||
delay(1); // delay in between reads for stability
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user