I implemented a mechanism where when you press a button for 3-sec, the latching relay switches its state.
The button's interrupt is falling-edge triggered.
The mechanism goes like this:
1. Button is pressed.
2. A timer checks every 100ms whether the button is still press.
3. If after 4 checks or less, the button is not pressed (i.e. a momentary pressing), a LED blinks.
4. If after 30 checks, the button is still pressed, the relay is switched.
5. Mechanism is stopped until next press.
1. Problem #1 is that when I press the button for 6sec (nonstop), The relay switches its state firstly after 3sec, and secondly after another 3sec.
However, it isnt supposed to happen according to the mechanism I wrote.
Moreover, When I debug the unit, without enough voltage for the relay driver to operate, and press the button for 6sec, the unit commands the relay to switch only once.
2. Problem #2 is that sometimes when I lift my finger from the button, after the relay was switched, it simulates a momentary pressing on the button.
I know that since when a momentary pressing happen, the LED blinks.
How can I solve these problems?
Thank you.
The button's interrupt is falling-edge triggered.
The mechanism goes like this:
1. Button is pressed.
2. A timer checks every 100ms whether the button is still press.
3. If after 4 checks or less, the button is not pressed (i.e. a momentary pressing), a LED blinks.
4. If after 30 checks, the button is still pressed, the relay is switched.
5. Mechanism is stopped until next press.
1. Problem #1 is that when I press the button for 6sec (nonstop), The relay switches its state firstly after 3sec, and secondly after another 3sec.
However, it isnt supposed to happen according to the mechanism I wrote.
Moreover, When I debug the unit, without enough voltage for the relay driver to operate, and press the button for 6sec, the unit commands the relay to switch only once.
2. Problem #2 is that sometimes when I lift my finger from the button, after the relay was switched, it simulates a momentary pressing on the button.
I know that since when a momentary pressing happen, the LED blinks.
How can I solve these problems?
Thank you.
Last edited: