void setup() { pinMode( PUSH2, INPUT_PULLUP ); Serial.begin( 9600 ); Serial.println( "Push button three times" ); } // // Detect the instant we are sure the switch has just closed // bool closed( void ) { static unsigned short s = 0; s <<= 1; s |= digitalRead( PUSH2 ); s |= 0xE000; // If we see any of four states open if( s == 0xF000 ) // followed by 12 closed states in a row return true; // then we have detected the edge return false; // Otherwise the switch is still open } unsigned count = 0; void loop() { if( closed() ) count++; if( count > 2 ) { Serial.println( "Three!" ); count = 0; } }