What I'm trying to make is a digital lock that has 4 buttons. 3 buttons are used to enter the code and the last button is used as an "unlock" button.
One of the features that I want to do is when you hold the "unlock" button for 5 sec, the circuit will go into code change mode where you can change your unlock code.
What's the best way to detect when a user holds down the unlock button for 5 sec or more? I can't dedicate a timer to this feature.
RLScott
Joined: 10 Jul 2007 Posts: 465
Re: What's the best way to write this code?
Posted: Tue Nov 25, 2008 7:39 am
david90 wrote:
I'm using PIC16F676 so I have limited resources.
What I'm trying to make is a digital lock that has 4 buttons. 3 buttons are used to enter the code and the last button is used as an "unlock" button.
One of the features that I want to do is when you hold the "unlock" button for 5 sec, the circuit will go into code change mode where you can change your unlock code.
What's the best way to detect when a user holds down the unlock button for 5 sec or more? I can't dedicate a timer to this feature.
First you must consider debouncing. If the code has nothing else to do when buttons are pushed, then you can poll for buttons and busy-wait whenever a button is pressed. During the busy-wait, you can use instruction timing or a hardware timer to determine how low a button is held down. Integrate debouncing into that busy-wait so that when a button is first detected as pressed or released, the press or release recognition should be delayed until the press or release has continued for a certain minimum period. A good way to do this is to increment a variable with a ceiling limit whenever the button is detected as pressed and decrement that variable with a floor limit whenever the button is detected as released. When the variable hits the ceiling or the floor you can take whatever recognition action is required. _________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum