I've been working on an aneometer for arduino using a Hall effect sensor, and I've gotten it to output current wind speeds to an LCD Display. What I'd like to add to this, is an output of average wind speed.
Heres what I have so far
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int pin = 2;
float mph; //variable for current mph
float ave; //variable for average mph
float duration; //variable for time between sensor pulses
int count = 0;void setup(){
pinMode(pin, INPUT);
lcd.begin(16, 2);
Serial.begin(9600);
}void loop(){
duration = pulseIn(pin, HIGH); //count how long pin is HIGH
mph = (0.00004412)/(duration/3600000000); //calculate mph
lcd.print("Current:");
lcd.setCursor(9, 0);
lcd.print(mph);
lcd.setCursor(13, 0);
lcd.print("mph");
lcd.setCursor(0, 1);
lcd.print("Average:");
lcd.setCursor(9, 1);
lcd.print(ave);
lcd.setCursor(13, 1);
lcd.print("mph");
}
Someone suggested I use an interrupt, but I'm not sure how to implement that information, either into what I have now or into a new program.