button debouncing for arduino

I found this bit of code:

boolean DebounceSwitch2() {
      int State = 0;
      State=(State<<1) | !RawKeyPressed() | 0xe000;
      if (State==0x000)
            return true;
      return false;
}

I'm trying to "port" this to Arduino. I'm pretty sure that RawKeyPressed() would be the same as digitalRead() (for my purposes), but exactly what does the whole line mean?

      State=(State<<1) | !RawKeyPressed() | 0xe000;

Gabe

AFAICT, that code doesn't work (it will always return false), and even if it did, it seems much too clever for what it's trying to do.

I just posted a new example on the tutorial page: http://www.arduino.cc/en/Tutorial/Switch

It uses a pushbutton as a switch to toggle an LED on and off, and debounces the switch input. Does it help?

I ended up doing almost the exact thing as you:

  newState = digitalRead(inPin);

  if ( (newState != prevState) && (timer + bounceTime < millis()) ){
    timer = millis();    //record time of output
    Serial.print((inPin*10)+newState);
  }
  
  prevState = newState;

Works great so far with my cheap, cheap button!

Gabe