Hi everyone, I have stripped a weather station code to test wind speed only, and it counts not one increment but two. Obviously a line missing, but have no idea what it should be…if anyone has any suggestions or another simple interrupt counter I could use to work it out that would be great.
Using LoraWan, and the interface extension board. Code below…
#define WIND_SPEED_SENSOR WB_IO1
int windSpeedCount;
int windSpeedSensorPrev;
unsigned long lastWindSpeedTime;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SETUP
void setup()
{
Serial.begin(115200);
pinMode(WIND_SPEED_SENSOR, INPUT_PULLUP);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ LOOP
void loop(){
unsigned long timeNow = millis();
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Do all the time +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++ Measure Wind Speed ++++++++++++++++++++++++++++++++++
// Time to check wind speed sensor?
if (timeNow - lastWindSpeedTime >= 1) {
lastWindSpeedTime += 1;
}
// Check wind speed sensor
int windSpeedSensor = digitalRead(WIND_SPEED_SENSOR);
if (windSpeedSensor != windSpeedSensorPrev) {
// Sensor has changed
windSpeedCount++;
windSpeedSensorPrev = windSpeedSensor;
}
Serial.println(windSpeedCount);
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
}