Thank you for this.
Now I know what to read and how to think about this.
I accidentally submitted without finishing.
After few hours of reading this morning, I also think that I have dug up the reason why i need to repair the code.
Signal is AC, the first code runs fast enough to detect positive side more than once in a millisecond.
And the doorlock is opened.
The second code detects voltage positive also and then in the next milli() it detects the end of ringing. The problem is in my ringing part of the code. I will all the same use "IF" = ).
I have posted another thread about counting frequency. But that is too far and advanced. This should work once I fix it. Will postback the final solution.