Reliable Debounce Circuit

This works with some very bouncy swtiches
The macro assumes non-blocking code and at least 4 readings. The value becomes true if you have exactly 1low and 3high consecutive readings.

Example:

//macro for detection and debouncing of raising edge
#define RE(signal, state) (state=(state<<1)|(signal&1)&15)==7

int buttonstate;
const int button = 2;
const int LED = 13;

void setup(){
  pinMode(LED, OUTPUT);
}//setup()

void loop(){
  if(RE(digitalRead(button), buttonstate)) digitalWrite(LED, !digitalRead(LED));//toggle led
}//loop()