2022-05-15 22:34:36 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
#include "config_user.h"
|
2022-05-15 22:34:36 +02:00
|
|
|
#include "config.h"
|
2019-08-04 11:56:18 +02:00
|
|
|
|
2022-05-15 22:34:36 +02:00
|
|
|
unsigned int anemometerRotations = 0;
|
2019-08-04 11:56:18 +02:00
|
|
|
|
2022-05-15 22:34:36 +02:00
|
|
|
ICACHE_RAM_ATTR void _anemometerInterrupt()
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
anemometerRotations++;
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.print("*");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:45:08 +02:00
|
|
|
float wind_speed()
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
anemometerRotations = 0;
|
2022-05-15 22:34:36 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
|
|
|
|
|
|
|
|
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING);
|
2022-05-15 22:34:36 +02:00
|
|
|
delay(1000 * WIND_SENSOR_MEAS_TIME_S); // time to measure
|
2019-08-04 11:56:18 +02:00
|
|
|
detachInterrupt(interruptNumber);
|
|
|
|
|
2022-05-16 10:45:08 +02:00
|
|
|
// calculate the speed as km/h
|
2022-05-18 19:08:55 +02:00
|
|
|
float tmp_speed = (float)anemometerRotations * WINDSPEED_FACTOR;
|
2022-05-16 10:45:08 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
Serial.print("Windspeed: " + String(tmp_speed));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return tmp_speed;
|
2022-05-15 22:34:36 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
}
|