I'm reading output from an anemometer and want to save the maximum wind speed as the readings come in. I've thought this through and can't come up with a solution. I want to save an input, then compare it to the next, and display it if is larger. Then, save the larger and compare it again to find the next larger, and so on. Not sure how to do this.
Help is greatly appreciated. Thanks.
Program below:
//This Sketch reads pulses sent by an anemometer
//from a hall effect sensor and calculates miles
//per hour.
float MPH;
float RPM;
unsigned long startTime;
const byte hallInputPin = 5;
unsigned long elapsedTime = 0;
unsigned long Count = 0;
unsigned long Sense;
unsigned long lastSense;
void setup() {
pinMode(hallInputPin, INPUT);
startTime = millis();
Serial.begin(9600);
}
void loop() {
Sense = digitalRead(hallInputPin);
if (lastSense != Sense) {
lastSense = Sense;
if (Sense == LOW) {
Count = Count + 1;
}
}
if (Count == 3) {
elapsedTime = millis() - startTime;
startTime = millis();
RPM = 18000 / elapsedTime;
MPH = RPM * .15;
Serial.print("MPH = ");
Serial.println (MPH);
Count = 0;
}
}