const int P1 = 2; // Broche pour le bouton P1
const int P2 = 3; // Broche pour le bouton P2
const int L1 = 13; // Broche pour la LED L1

#define relache HIGH
#define appui LOW

#define nochange 0
#define appuiP1 1
#define relacheP1 2
#define appuiP2 3
#define relacheP2 4
#define toucheP1 digitalRead(P1)
#define toucheP2 digitalRead(P2)

byte sequence[] = {appuiP1, relacheP1, appuiP1, appuiP2, relacheP2, relacheP1}; // Séquence à détecter
int longeurSequence;
int seqIndex = 0; // Index de la séquence à vérifier
int touche;

void setup() {//*************************setup************************
  Serial.begin(9600);
  pinMode(P1, INPUT_PULLUP);
  pinMode(P2, INPUT_PULLUP);
  pinMode(L1, OUTPUT);
  longeurSequence = sizeof(sequence);
}
void loop() {//**************************loop***********************
   int time_key_read = millis();
   static int last_key_read ;
   touche=nochange;
   if (time_key_read - last_key_read >= 100) {                         // Vérifier si au moins 100ms se sont écoulées depuis la dernière lecture du bouton
          last_key_read = time_key_read;
          touche = scanButtons();
   }
  if(touche != nochange){ 
        Serial.print(touche);
        if(touche != sequence[seqIndex]){seqIndex=-1;}
        seqIndex++;
        if(seqIndex == longeurSequence){
                        Serial.print("ok ");
                        digitalWrite(L1, HIGH);
                        delay(3000);
                        digitalWrite(L1, LOW);
                        seqIndex=0;
        }
      
  }
  
}

int scanButtons() {   
  static int lastStateP1 = 1;
  static int lastStateP2 = 3;
  int currentStateP1 = toucheP1;
  int currentStateP2 = toucheP2;
  
  if (currentStateP1 != lastStateP1) {    //changement etat p1 
    lastStateP1 = currentStateP1;
    return currentStateP1 == appui ? appuiP1 : relacheP1;
  }
  if (currentStateP2 != lastStateP2) {     //changement etat p2 
    lastStateP2 = currentStateP2;
    return currentStateP2 == appui ? appuiP2 : relacheP2;
  }
  return nochange;                                // Rien n'a changé
}
Appui sur P1 P2 ou sur clavier touche numerique 1 et 2
Sequence pour allumer Led appuiP1, relacheP1, appuiP1, appuiP2, relacheP2, relacheP1