weatherstation/firmware/sensor_wind.ino

23 lines
513 B
C++
Executable file

#include "config_user.h"
int anemometerRotations = 0;
unsigned long currentTime = 0;
ICACHE_RAM_ATTR void _anemometerInterrupt() {
anemometerRotations++;
#ifdef DEBUG
Serial.print("*");
#endif
}
float wind_speed() {
anemometerRotations = 0;
currentTime = millis();
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING);
delay(1000 * 5);
detachInterrupt(interruptNumber);
return (float)anemometerRotations / 5.0 * 2.4;
}