My Debounce Function, Opinions?

Hey guys, the only debouncing during interrupts I found on here was a library holding a class that I didn't understand so I wrote my own function:

void debounce(){
  boolean temp = false;
  while( temp == false ){
    shift = shift << 1;
    if( digitalRead( BUTTON ) == LOW ){
      shift = shift + 1;  
    }
    if( shift == 0xFFFF ){
      temp = true; 
    }
  }
}

EDIT: So I think it would be best if shift was an unsigned long and the if condition should read: if( shift == 0xFFFFFFFF ){

To sum it up, it acts like a shift register that shifts in zeros but will add 1 anytime the button stays low. So whenever it bounces up there will be a zero that has to be shifted all the way through.

I'm not sure that I understand what you are doing, or why, but it appears as though this function will block for a long time.

The only way for this function to return is for temp to be true, and the only way for temp to be true is for shift to be 0xFFFF.

Without knowing what type shift is, it's hard to say if shift will ever be 0xFFFF.

Another thing. This function does not return a value, or take any arguments. How is it (to be) used?

This function bit shifts the variable 'shift' every loop. If the button is LOW like it is supposed to be, it will add 1 to fill that shifted bit in, otherwise there is a zero there that will be shifted through. The function just waits until every bit is a 1. In other words, the BUTTON is constantly LOW.

That makes sense, I guess. But how is the function used? It takes no arguments, and returns nothing. The only global variable always has the same value when the function does end. Why is that variable global, anyway?

Ok that debounce function did not work as I wanted it lol. I ended up just doing:

delayMicroseconds(20000);
if( digitalRead( BUTTON ) == HIGH ){
return;
}

which works like a charm for falling edge interrupts.

Use this library: Arduino Playground - Bounce