Page 1 of 1

watchDogNotification fix - isOpen delay

PostPosted: Fri Aug 30, 2013 10:32 am
by ToddG
Another problem I was having was that the isOpen function was reading the pin status so fast that I was getting a false-negative intermittently/every-so-often when the door was open. This would cause the watchDogNotificationsHandler to reset the notificationSent variable resulting in no notification. The simple fix here was to slow things down and add a short delay to the isOpen function.

//----------------------------------------------------------------------------------------------------
boolean isOpen(int pinNumber)
{
#if defined(STATUS_STRATEGY_3VCLOSED_5VOPENED) || defined(STATUS_STRATEGY_5VCLOSED_3VOPENED)
int status = analogRead(pinNumber);
#elif defined(STATUS_STRATEGY_NORMALLY_CLOSED) || defined(STATUS_STRATEGY_NORMALLY_OPENED)
int status = digitalRead(pinNumber+14); // addressing analog pins as digital pins (+14)
#endif

// Added to help with misses on status pin reading. - TSG 8/29/2013
delay(1000);


... I also added a comment for debugging further down in the function.

#if defined(MYDOOROPENER_SERIAL_DEBUGGING)
Serial.print(F("' returning: '"));
Serial.print(retVal ? F("Opened") : F("Closed"));
Serial.println(F("' ***"));
// Added to help with misses on status pin reading. - TSG 8/29/2013
Serial.println(F("Sleeping for 1 second..."));
#endif

return retVal;
}

//----------------------------------------------------------------------------------------------------