Break Stuff
Active member
I expected analogReadAveraging(200);
to smooth out the jittery results of analogRead(0);
Yet it has no discernible effect that I can see.
The blue line is very much having a caffeine overdose:
While the red line, using my clunky manual averaging is just chillin' with some ice tea on the porch:
to smooth out the jittery results of analogRead(0);
Yet it has no discernible effect that I can see.
The blue line is very much having a caffeine overdose:
Code:
void setup() {
analogReadAveraging(200);
}
void loop() {
Serial.print(analogRead(0));
Serial.print(" "); //for serial plotter visual scaling
Serial.print(1200); //for serial plotter visual scaling
Serial.print(" "); //for serial plotter visual scaling
Serial.println(0); //for serial plotter visual scaling
}
While the red line, using my clunky manual averaging is just chillin' with some ice tea on the porch:
Code:
void setup() {
}
void loop() {
const int averaging = 200; // how many to average
static int x[averaging]; // array of values to average
int xAVG = 0; // store average result
for (int i = averaging - 1; i > 0; i--) { x[i] = x[i-1];} //move each value to the next spot in array
x[0] = analogRead(0); //fill first value of array with most recent
for (int i = 0; i < averaging; i++) { xAVG += x[i]; } // add all values of array together
xAVG = xAVG/averaging; // divide by number of values to get average
Serial.print(1200); //for serial plotter visual scaling
Serial.print(" ");//for serial plotter visual scaling
Serial.print(xAVG); // print average
Serial.print(" ");//for serial plotter visual scaling
Serial.println(0);//for serial plotter visual scaling
}