#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); // calculate the speed as km/h float tmp_speed = (float)anemometerRotations * WINDSPEED_FACTOR; #ifdef DEBUG Serial.print("Windspeed: " + String(tmp_speed)); #endif return tmp_speed; }