Chouette un concours de simplicité (ou de complexité suivant le point de vue ;))
Voyons si on peut faire plus simple que Skywodd
const byte broche_bp[] = {A0, A1, A2, A3, A4, A5, 2, 3 }; // Broches des boutons
const byte broche_led[] = {4, 5, 6, 7, 8, 9, 10, 11}; // Broches des leds
byte last_pressed = 0;
void setup() {
for(byte i = 0; i < sizeof(broche_bp); ++i) {
pinMode(broche_bp[i], INPUT);
pinMode(broche_led[i], OUTPUT);
}
}
void loop()
{
for(byte i = 0; i < sizeof(broche_bp); ++i) { // On scan chaque boutons
if( digitalRead(broche_bp[i]) == HIGH ) { // Si le boutons est appuyé
digitalWrite( last_pressed, LOW ); // on éteint la LED précédente, marche aussi si la précédente est la même que la courante
if ( i != last_pressed ) // on allume la led si différente de la précédente
digitalWrite( broche_led[i], HIGH );
last_pressed = i; // on mémorise la nouvelle led courante
while ( digitalRead(broche_bp[i]) == HIGH ); // on attend le relaché
break; // on sort du for
}
}
}
Une boucle et un tableau en moins.