#include "./pitches.h" 
int melody1[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; 
int melody2[] = { NOTE_C4, NOTE_B3, 0, NOTE_G3, NOTE_A3, NOTE_G3,NOTE_G3, NOTE_C4 }; 
int noteDurations1[] = { 8, 16, 16, 8, 8, 8, 8, 8 }; 
int noteDurations2[] = { 8, 8, 8, 8, 8, 16, 16, 8 }; 
int playtone(int melody[], int noteDurations[]) { 
    for (int thisNote = 0; thisNote < 8; thisNote++) {
        int noteDuration = 1000 / noteDurations[thisNote]; 
        tone(7, melody[thisNote], noteDuration);
        int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); 
        noTone(7); 
    }
}; 

const int buttonPinReset = 8; 
const int buttonPinA = 1; 
const int buttonPinB = 2; 
const int ledPinB = 5; 
const int ledPinG = 6; 
unsigned long StartTime; 
int ButtonAWasPressedOnce=0; 
int ButtonBWasPressedOnce=0; 
volatile int buttonStateReset = HIGH; 
volatile int buttonStateA = HIGH; 
volatile int buttonStateB = HIGH; 

void myButtonPinAAction () { 
    if (buttonStateB == HIGH) buttonStateA = LOW; 
} 
void myButtonPinBAction () {
    if (buttonStateA == HIGH) buttonStateB = LOW; 
} 
    
void setup() { 
    pinMode(buttonPinReset, INPUT_PULLUP); 
    pinMode(buttonPinA, INPUT_PULLUP); 
    pinMode(buttonPinB, INPUT_PULLUP); 
    pinMode(ledPinB, OUTPUT); 
    pinMode(ledPinG, OUTPUT); 
    StartTime = millis(); 
    Keyboard.begin(); 
    attachInterrupt(digitalPinToInterrupt(buttonPinA), myButtonPinAAction, FALLING); 
    attachInterrupt(digitalPinToInterrupt(buttonPinB), myButtonPinBAction, FALLING); 
} 

void loop() { 
/* 
see attach Interrupts
buttonStateA = digitalRead(buttonPinA); 
buttonStateB = digitalRead(buttonPinB);
*/ 
if (buttonStateA == LOW) { 
    digitalWrite(ledPinB, HIGH); 
    playtone(melody1,noteDurations1); 
    while (digitalRead(buttonPinReset) == HIGH) {}; 
    ButtonAWasPressedOnce=1; 
    digitalWrite(ledPinG, HIGH); 
    playtone(melody2,noteDurations2); 
    while (digitalRead(buttonPinReset) == HIGH) {}; 
    ButtonBWasPressedOnce=1; 
    digitalWrite(ledPinG, LOW); 
    buttonStateB = HIGH; 
} else if (((millis() - StartTime)>1500) && ((ButtonAWasPressedOnce + ButtonBWasPressedOnce ) > 1)) { 
    Keyboard.print(" "); StartTime=millis(); 
} }

 

NotAus faster PushButtonGame