weatherstation/firmware/sensor_wind.ino

26 lines
532 B
C++

#include "config_user.h"
#include "config.h"
unsigned int anemometerRotations = 0;
ICACHE_RAM_ATTR void _anemometerInterrupt()
{
anemometerRotations++;
#ifdef DEBUG
Serial.print("*");
#endif
}
float wind_speed() {
anemometerRotations = 0;
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING);
delay(1000 * WIND_SENSOR_MEAS_TIME_S); // time to measure
detachInterrupt(interruptNumber);
return (float)anemometerRotations * COUNT_TO_KMH;
}