Looking for routine to debounce buttons in C

Status
Not open for further replies.

micpic

Junior Member level 3
Joined
Apr 18, 2005
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,498
c debounce

Hello,

has somebodey a routine to debounce some buttons (written in c)?
I am searching for something which worjs without delays, so that the µC isn´t blocked while debouncing.
 

debounce em c

u don't require special routine for for debouncing u might make some small delay routine then check again if the button is pressed
 

Re: Debouncing in C

You could use a while loop like this:

int button=0

//when the button is initially pressed, set the variable button=1

while(button == 1)
if(button==1)
button==1
elseif(button!=1)
button=0
break //break out of the loop once the button has been let go
endif
end
 

Re: Debouncing in C

micpic said:
Hello,

has somebodey a routine to debounce some buttons (written in c)?
I am searching for something which worjs without delays, so that the µC isn´t blocked while debouncing.

Then use timers , and timer interrupt

/Bingo
 

Debouncing in C

you can use a rutine in timer

like

if ( key != old_key ) {
debounce--;
if ( debounce == 0 ){
key_pressed = key;
debounce = 100;
}
}
else{
debounce = 100;
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…