I’m sure this is probably something quite obvious but I can’t figure it out…or haven’t been able to yet.
I’m trying to monitor a front door in two different ways:
If the doorbell has been rung, I’m trying to monitor if the door actually gets opened within a minute. If not, do stuff().
If the door is opened WITHOUT the doorbell having been rung, I’m trying to do otherstuff().
I’ve more or less got this working, but bizarrely I seem to have a delay somewhere before the Core recognises that the reed switch state has changed. I’m wondering if anyone might have some insight into where this delay is introduced? It’s not hugely important in terms of the functioning of the system I’m trying to build, but I think it probably points at a problem with the system which might cause me OTHER problems down the line (like the front doorbell being pushed being missed!)
(code is at link above, I hope this is an OK way to post code??)
Posting my loop here
reedswitch = digitalRead(DoorReed);
if (reedswitch == HIGH && DoorBellPushed == 1)
DoorAnswered = 1;
DoorBellPushed = 0;
Serial << "Doorbell answered\n";
if (reedswitch == HIGH && DoorBellPushed == 0)
//Serial << "Door opened with key";
if (reedswitch == LOW && DoorBellPushed == 1)
//Serial << "Waiting for an answer";
if (reedswitch == LOW && DoorBellPushed == 0)
//Serial << "Nothin' doing";
How much of a delay are you talking about? You could put a Serial.println(millis()) statement as the first line in loop, and after each of the next statements before the if. That should at least narrow down where the problem lies.
Thanks @Ric - I haven’t a clue why but I tried the exact same code on the exact same device a couple of days later and no delay was present. Weird.