Tutorial.Smoothing History

Hide minor edits - Show changes to markup

June 04, 2010, at 11:38 PM by Equipo Traduccion -
Changed lines 14-16 from:

Imagen desarrollada utilizando Fritzing. Para más ejemplos de circuitos, mira la página de proyectos de Fritzing

to:

Imagen desarrollada utilizando Fritzing. Para más ejemplos de circuitos, mira la página de proyectos de Fritzing.

June 04, 2010, at 11:22 PM by Equipo Traduccion -
Changed lines 14-16 from:

imagen desarrollada utilizando Fritzing. Para más ejemplos de circuitos, mira la página de proyectos de Fritzing

to:

Imagen desarrollada utilizando Fritzing. Para más ejemplos de circuitos, mira la página de proyectos de Fritzing

June 04, 2010, at 11:21 PM by Equipo Traduccion -
Changed lines 5-6 from:

Lee repetidamente desde una entrada analógica, calculando la media y lo escribe en el ordenador. Demuestra el uso de matrices.

to:

Lee repetidamente desde una entrada analógica, calculando la media y la escribe en el ordenador. Demuestra el uso de matrices.

June 04, 2010, at 11:20 PM by Equipo Traduccion -
Changed lines 1-2 from:

Examples > Analog I/O

to:

Ejemplos > E/S analógicas

Changed lines 5-11 from:

Reads repeatedly from an analog input, calculating a running average and printing it to the computer. Demonstrates the use of arrays.

Circuit

Potentiometer on analog input pin 0.

click the image to enlarge

to:

Lee repetidamente desde una entrada analógica, calculando la media y lo escribe en el ordenador. Demuestra el uso de matrices.

Circuito

Potenciómetro en la entrada analógica 0.

Haz click e la imagen para ampliarla

Changed lines 14-19 from:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

click the image to enlarge

to:

imagen desarrollada utilizando Fritzing. Para más ejemplos de circuitos, mira la página de proyectos de Fritzing

Esquema

Haz click e la imagen para ampliarla

Changed line 23 from:

Code

to:

Código

February 23, 2010, at 07:59 PM by Tom Igoe -
Changed line 26 from:
 /*
to:
Deleted lines 27-89:
   Smoothing

   Reads repeatedly from an analog input, calculating a running average
   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

   Created 22 April 2007
   By David A. Mellis  <dam@mellis.org>

   http://www.arduino.cc/en/Tutorial/Smoothing

 */

 // Define the number of samples to keep track of.  The higher the number,
 // the more the readings will be smoothed, but the slower the output will
 // respond to the input.  Using a constant rather than a normal variable lets
 // use this value to determine the size of the readings array.
 const int numReadings = 10;

 int readings[numReadings];      // the readings from the analog input
 int index = 0;                  // the index of the current reading
 int total = 0;                  // the running total
 int average = 0;                // the average

 int inputPin = 0;

 void setup()
 {
   // initialize serial communication with computer:
   Serial.begin(9600);                   
   // initialize all the readings to 0: 
   for (int thisReading = 0; thisReading < numReadings; thisReading++)
     readings[thisReading] = 0;          
 }

 void loop() {
   // subtract the last reading:
   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;                    

   // if we're at the end of the array...
   if (index >= numReadings)              
     // ...wrap around to the beginning: 
     index = 0;                           

   // calculate the average:
   average = total / numReadings;         
   // send it to the computer (as ASCII digits) 
   Serial.println(average, DEC);               
 }

August 27, 2009, at 08:46 PM by Tom Igoe -
Added lines 14-16:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

July 05, 2009, at 07:22 PM by Tom Igoe -
Changed lines 21-29 from:

[@ /*

  Smoothing

  Reads repeatedly from an analog input, calculating a running average
  and printing it to the computer.  Keeps ten readings in an array and 
  continually averages them.
to:
Changed lines 23-77 from:
  The circuit:
    * Analog sensor (potentiometer will do) attached to analog input 0

  Created 22 April 2007
  By David A. Mellis  <dam@mellis.org>

  http://www.arduino.cc/en/Tutorial/Smoothing

  • /

// Define the number of samples to keep track of. The higher the number, // the more the readings will be smoothed, but the slower the output will // respond to the input. Using a constant rather than a normal variable lets // use this value to determine the size of the readings array. const int numReadings = 10;

int readings[numReadings]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average

int inputPin = 0;

void setup() {

  // initialize serial communication with computer:
  Serial.begin(9600);                   
  // initialize all the readings to 0: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;          

}

void loop() {

  // subtract the last reading:
  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;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // send it to the computer (as ASCII digits) 
  Serial.println(average, DEC);               

} @]

to:
June 25, 2009, at 11:29 PM by Tom Igoe -
Added lines 11-19:

click the image to enlarge

Schematic

click the image to enlarge

June 17, 2009, at 11:30 PM by Tom Igoe -
Added lines 14-33:

/*

  Smoothing

  Reads repeatedly from an analog input, calculating a running average
  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

  Created 22 April 2007
  By David A. Mellis  <dam@mellis.org>

  http://www.arduino.cc/en/Tutorial/Smoothing

  • /

Changed line 36 from:

// respond to the input. Using a #define rather than a normal variable lets

to:

// respond to the input. Using a constant rather than a normal variable lets

Changed lines 38-44 from:
  1. define NUMREADINGS 10

int readings[NUMREADINGS]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average

to:

const int numReadings = 10;

int readings[numReadings]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average

Changed lines 49-51 from:
  Serial.begin(9600);                     // initialize serial communication with computer
  for (int i = 0; i < NUMREADINGS; i++)
    readings[i] = 0;                      // initialize all the readings to 0
to:
  // initialize serial communication with computer:
  Serial.begin(9600);                   
  // initialize all the readings to 0: 
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;          
Changed lines 56-67 from:

void loop() {

  total -= readings[index];               // subtract the last reading
  readings[index] = analogRead(inputPin); // read from the sensor
  total += readings[index];               // add the reading to the total
  index = (index + 1);                    // advance to the next index

  if (index >= NUMREADINGS)               // if we're at the end of the array...
    index = 0;                            // ...wrap around to the beginning

  average = total / NUMREADINGS;          // calculate the average
  Serial.println(average);                // send it to the computer (as ASCII digits)
to:

void loop() {

  // subtract the last reading:
  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;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // send it to the computer (as ASCII digits) 
  Serial.println(average, DEC);               
April 22, 2007, at 07:19 PM by David A. Mellis -
Changed lines 5-6 from:

Reads repeatedly from an analog input, calculating a running average and outputting it to an analog output. Demonstrates the use of arrays.

to:

Reads repeatedly from an analog input, calculating a running average and printing it to the computer. Demonstrates the use of arrays.

Changed lines 9-10 from:

Potentiometer on analog input pin 0, LED on pin 9.

to:

Potentiometer on analog input pin 0.

Deleted lines 13-22:

/*

 * Smoothing
 * David A. Mellis <dam@mellis.org>
 *
 * Reads repeatedly from an analog input, calculating a running average
 * and outputting it to an analog output. 
 *
 * http://www.arduino.cc/en/Tutorial/Smoothing
 */
Changed lines 26-27 from:

int outputPin = 9;

to:
Added line 29:
  Serial.begin(9600);                     // initialize serial communication with computer
Changed line 45 from:
  analogWrite(outputPin, average / 4);    // analog inputs go up to 1023, outputs to 255
to:
  Serial.println(average);                // send it to the computer (as ASCII digits)
March 25, 2007, at 10:02 AM by David A. Mellis -
Added lines 1-12:

Examples > Analog I/O

Smoothing

Reads repeatedly from an analog input, calculating a running average and outputting it to an analog output. Demonstrates the use of arrays.

Circuit

Potentiometer on analog input pin 0, LED on pin 9.

Code

Changed lines 14-22 from:
  1. define NUMSAMPLES 10

int samples[NUMSAMPLES]; int index = 0; int total = 0;

int sensor = 0; int actuator = 9;

to:

/*

 * Smoothing
 * David A. Mellis <dam@mellis.org>
 *
 * Reads repeatedly from an analog input, calculating a running average
 * and outputting it to an analog output. 
 *
 * http://www.arduino.cc/en/Tutorial/Smoothing
 */

// Define the number of samples to keep track of. The higher the number, // the more the readings will be smoothed, but the slower the output will // respond to the input. Using a #define rather than a normal variable lets // use this value to determine the size of the readings array.

  1. define NUMREADINGS 10

int readings[NUMREADINGS]; // the readings from the analog input int index = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average

int inputPin = 0; int outputPin = 9;

Changed lines 40-41 from:
  for (int i = 0; i < NUMSAMPLES; i++)
    samples[i] = 0;
to:
  for (int i = 0; i < NUMREADINGS; i++)
    readings[i] = 0;                      // initialize all the readings to 0
Changed lines 46-50 from:
  total -= samples[index];
  samples[index] = analogRead(sensor);
  total += samples[index];
  index = (index + 1) % NUMSAMPLES;
  analogWrite(actuator, total / NUMSAMPLES);
to:
  total -= readings[index];               // subtract the last reading
  readings[index] = analogRead(inputPin); // read from the sensor
  total += readings[index];               // add the reading to the total
  index = (index + 1);                    // advance to the next index

  if (index >= NUMREADINGS)               // if we're at the end of the array...
    index = 0;                            // ...wrap around to the beginning

  average = total / NUMREADINGS;          // calculate the average
  analogWrite(outputPin, average / 4);    // analog inputs go up to 1023, outputs to 255
January 14, 2007, at 03:28 PM by David A. Mellis -
Added line 1:

[@

Added line 25:

@]

January 14, 2007, at 03:28 PM by David A. Mellis -
Added lines 1-23:
  1. define NUMSAMPLES 10

int samples[NUMSAMPLES]; int index = 0; int total = 0;

int sensor = 0; int actuator = 9;

void setup() {

  for (int i = 0; i < NUMSAMPLES; i++)
    samples[i] = 0;

}

void loop() {

  total -= samples[index];
  samples[index] = analogRead(sensor);
  total += samples[index];
  index = (index + 1) % NUMSAMPLES;
  analogWrite(actuator, total / NUMSAMPLES);

}

Share