Read serial data into array for smoothing filter
i'm newbie , trying smoothing data...
the data in 14byte cr n nl....
pls me
for exm= 0000.1000010
0000.2000010
0001.1000010
0000.1000010
0000.1000010
0000.1000010
0000.1000010
0000.1000010
i'm refer code
/*
smoothing
reads repeatedly analog input, calculating running average
, printing computer. keeps ten readings in array and
continually averages them.
circuit:
* analog sensor (potentiometer do) attached analog input 0
created 22 april 2007
david a. mellis <dam@mellis.org>
modified 9 apr 2012
tom igoe
http://www.arduino.cc/en/tutorial/smoothing
example code in public domain.
*/
// define number of samples keep track of. higher number,
// more readings smoothed, slower output will
// respond input. using constant rather normal variable lets
// use value determine size of readings array.
const int numreadings = 10;
int readings[numreadings]; // readings analog input
char readindex = 0; // index of current reading
int total = 0; // running total
int average = 0; // average
int inputpin = a0;
void setup() {
// initialize serial communication computer:
serial.begin(9600);
// initialize readings 0:
(int thisreading = 0; thisreading < numreadings; thisreading++) {
readings[thisreading] = 0;
}
}
void loop() {
// subtract last reading:
total = total - readings[readindex];
// read sensor:
readings[readindex] = analogread(inputpin);
// add reading total:
total = total + readings[readindex];
// advance next position in array:
readindex = readindex + 1;
// if we're @ end of array...
if (readindex >= numreadings) {
// ...wrap around beginning:
readindex = 0;
}
// calculate average:
average = total / numreadings;
// send computer ascii digits
serial.println(average);
delay(500); // delay in between reads stability
}
the data in 14byte cr n nl....
pls me
for exm= 0000.1000010
0000.2000010
0001.1000010
0000.1000010
0000.1000010
0000.1000010
0000.1000010
0000.1000010
i'm refer code
/*
smoothing
reads repeatedly analog input, calculating running average
, printing computer. keeps ten readings in array and
continually averages them.
circuit:
* analog sensor (potentiometer do) attached analog input 0
created 22 april 2007
david a. mellis <dam@mellis.org>
modified 9 apr 2012
tom igoe
http://www.arduino.cc/en/tutorial/smoothing
example code in public domain.
*/
// define number of samples keep track of. higher number,
// more readings smoothed, slower output will
// respond input. using constant rather normal variable lets
// use value determine size of readings array.
const int numreadings = 10;
int readings[numreadings]; // readings analog input
char readindex = 0; // index of current reading
int total = 0; // running total
int average = 0; // average
int inputpin = a0;
void setup() {
// initialize serial communication computer:
serial.begin(9600);
// initialize readings 0:
(int thisreading = 0; thisreading < numreadings; thisreading++) {
readings[thisreading] = 0;
}
}
void loop() {
// subtract last reading:
total = total - readings[readindex];
// read sensor:
readings[readindex] = analogread(inputpin);
// add reading total:
total = total + readings[readindex];
// advance next position in array:
readindex = readindex + 1;
// if we're @ end of array...
if (readindex >= numreadings) {
// ...wrap around beginning:
readindex = 0;
}
// calculate average:
average = total / numreadings;
// send computer ascii digits
serial.println(average);
delay(500); // delay in between reads stability
}
ok, new. want smooth data. have sample that. understand. haven't stated need on.
what part of sketch not understand? need help?
what part of sketch not understand? need help?
Arduino Forum > Using Arduino > Programming Questions > Read serial data into array for smoothing filter
arduino
Comments
Post a Comment