Hi Guys!
It's a little later on in this project now and I went back to look at the anemometer readings I was getting and there are some one off readings where the wind speed suddenly just reads 0.00 mph then carries on reading the wind speed as usual.
Is it possible to modify the below code to get a rolling average of anemometer readings from the previous 10 readings?
const byte BUTTON = 2;
float elapsed, diff, start;
float windspeed;
// Begin Setup-----------------------------------------------------------------
void setup ()
{
Serial.begin(9600);
digitalWrite (BUTTON, HIGH); // internal pull-up resistor
attachInterrupt (0, pinChange, RISING); // attach interrupt handler
start = millis();
Serial.println("WindSpd");
}
// Interrupt Process for Windspeed Measurement---------------------------------
void pinChange ()
{
elapsed=millis()-start; //gets the full period (in ms) of rotation
windspeed=2.5/(elapsed/1000); //gets freq from ms then * by 2.5 to get mph
start=millis(); //resets the counter
}
// end of Interrupt Process----------------------------------------------------
// Main Loop-------------------------------------------------------------------
void loop ()
{
//Begin Serial Printing
Serial.print(windspeed);
Serial.print(" ");
Serial.println("mph");
//End Serial Printing
delay(200);
}