#define pot 35
int ADC_out;
const int windowSize = 10; // Has to be constant
int readings[windowSize]; // The size need to be constant
int readIndex = 0;
int total = 0;
int average = 0;
void setup()
{
Serial.begin(9600);
delay(100);
// reseting the values to zero
for(int i = 0; i < windowSize; i++)
{
readings[i] = 0;
}
}
void loop()
{
// removing the last reading from the total
total = total - readings[readIndex];
// read the ADC
readings[readIndex] = analogRead(pot);
// adding the reading to the total
total += readings[readIndex];
// Calculate the average
average = total/windowSize;
// Printing the result
Serial.print(readings[readIndex]);// This is the green line
Serial.print(",");
Serial.println(average); // This is the orange line
// updating the readIndex
readIndex = (readIndex + 1) % windowSize;
}