weatherstation/firmware/sensor_wind.ino
Florian Eitel be334245ff
Refactor sensor interface with extra files and function pointer
That makes it easier to enable/disable sensors.

Also added support for APDS9930
2019-08-04 12:53:20 +02:00

23 lines
513 B
C++

#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;
}