I used #include "LowPower.h" to sleep for about 60 sec after each reading of 10 sec).
it workes but only on the first iteration after that, it continues to execute every 10sec with no sleep like it wasn't there.
this is my main code
void loop() {
unsigned long rTime = millis();
if((rTime - sTime) > 2500) pulseTime = 0; //if the wind speed has dropped below 1MPH than set it to zero
if((rTime - dataTimer) > 10000){ //See if it is time to transmit
detachInterrupt(interruptPin); //shut off wind speed measurement interrupt until done communication
float aWSpeed = getAvgWindSpeed(culPulseTime,avgWindCount)*1.61; //calculate average wind speed
culPulseTime = 0; //reset cumulative pulse counter
avgWindCount = 0; //reset average wind count
float aFreq = 0; //set to zero initially
if(pulseTime > 0.0) aFreq = getAnemometerFreq(pulseTime); //calculate frequency in Hz of anemometer, only if pulsetime is non-zero
float wSpeedMPH = getWindMPH(aFreq); //calculate wind speed in MPH, note that the 2.5 comes from anemometer data sheet
//float wSpeedKPH = getWindKPH(wSpeedMPH); //calculate wind speed in MPH, note that the 2.5 comes from anemometer data sheet
Serial.begin(57600); //start serial monitor to communicate wind data
Serial.println(aWSpeed);
Serial.end(); //serial uses interrupts so we want to turn it off before we turn the wind measurement interrupts back on
for (int i = 0; i < 8; i++) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); // 8s is max for low.power lib, but with a 8 loops = 60sec
}
start = true; //reset start variable in case we missed wind data while communicating current data out
attachInterrupt(digitalPinToInterrupt(interruptPin), anemometerISR, RISING); //turn interrupt back on
dataTimer = millis(); //reset loop timer
}
}
this line is causing the issue but I don't understand why, and also why it's working once?
attachInterrupt(digitalPinToInterrupt(interruptPin), anemometerISR, RISING); //turn interrupt back on
Does anybody have an idea?