J-M-L:
The functions never run at the same time...
You arrive in IMM if the reed value is HIGH th microprocessor jumps to the ALL function and that’s what is executed. Then ALL terminates, you go back to where you came from and since this is all that you have in your while, the while ‘loops’ and test your REED sensor again, if it’s still HIGH you go back into ALL and the cycle continues.
If you want to call ALL only ONCE in IMM when the reed value is HIGH, don’t use a while
, use a if
statement
Please edit and fix your post and use code tags around the code. (see how to use the forum)
Hi everybody
Thanks for your replies.
I edited my first post as J-M-L suggested I also added some part of the entire sketch to explain the problem in a better way.
First of all, the whole sketch is about a multi-zone anti-theft system using PIR sensors, a gyroscope, reed switches (can be immediate or delayed), RFID for disarming, etc.
I didn't post the whole sketch for basically 2 reasons: it's already pretty big even though it's still incomplete, and many parts (functions, comments, etc.) are written in Italian.
Now, when i move the magnet away from the immediate reed (void IMM()) the ALL() function is run; so Buzzer, green and red leds are on. But if i move the magnet close to the reed sensor again, the buzzer keeps buzzing but the leds turn off.
Or if ALL() function is running because the immediateREED value was HIGH, and while the alarm is on (so buzzer and LEDs are on) I make the delayedREED value be HIGH as well, the buzzer keeps buzzing but the LEDs start blinking at the same sequences described in the PRE() function.
Both of the issues above happen if I use both "while" and "if".
I tried with the return as well, just after ALL() function is called...nothing's changed.
So I need a way to stop everything once ALL() in running, except the RFID() function that will allow me to disarm the alarm system.
I hope I made everything clearer now, and sorry for my typos or similar.
P.s. I haven't completely understood the functionNeedsToContinue and functionDecidesItsTimeToBreak stuff...