/*
######################################################################################################
# Question pour un Champion #
# Les BUZZERS de quatres joueurs #
######################################################################################################
*/
// *** Initialisation des variables ***
const int ButtonPin1 = 7; //
const int ButtonPin2 = 6; // Quatres boutons poussoirs pour
const int ButtonPin3 = 5; // faire les BUZZERS
const int ButtonPin4 = 4; //
const int ButtonPinRESET = 3; // Bouton RàZ
const int LedPin1 = 12; //
const int LedPin2 = 11; // Quatres LED pour faire
const int LedPin3 = 10; // le voyant du BUZZER le + Rapide
const int LedPin4 = 9; //
const int BUZZER = 13; // Sortie buzzer
int Buttonstate1 = 0; //
int Buttonstate2 = 0; // Initialisation des variables à 0
int Buttonstate3 = 0; //
int Buttonstate4 = 0; //
int ButtonstateRESET = 0; //
void setup ()
{
pinMode(LedPin1, OUTPUT); //
pinMode(LedPin2, OUTPUT); // Initialisation des LEDs en Sortie de l'Arduino
pinMode(LedPin3, OUTPUT); //
pinMode(LedPin4, OUTPUT); //
pinMode(BUZZER, OUTPUT); //
pinMode(ButtonPin1, INPUT); //
pinMode(ButtonPin2, INPUT); // Initialisation des Boutons en Entrée de l'Arduino
pinMode(ButtonPin3, INPUT); //
pinMode(ButtonPin4, INPUT); //
}
void loop ()
{
// Nous effectuons une lecture des boutons 1 à 4 ainsi que le bouton RESET,
// nous pouvons ensuite travailler sur les valeurs (Haut ou Bas) des boutons...
digitalWrite(LedPin1, LOW);
digitalWrite(LedPin2, LOW);
digitalWrite(LedPin3, LOW);
digitalWrite(LedPin4, LOW);
digitalWrite(BUZZER, LOW);
// ***---*** Etude de Cas ***---***
// *** Cas du Bouton 1 ***
Buttonstate1 = digitalRead(ButtonPin1);
if (Buttonstate1 == HIGH) // Si le bouton 1 est activé
{
digitalWrite(LedPin1, HIGH); // Allumer la Led du bouton 1
digitalWrite(BUZZER, HIGH); // Son du Buzzer activé
delay(1000);
digitalWrite(BUZZER, LOW); // Son du Buzzer désactivé
while ( ButtonstateRESET != HIGH)
{
ButtonstateRESET = digitalRead(ButtonPinRESET);
}
digitalWrite(LedPin1, LOW); // Eteindre la led du bouton 1
Buttonstate1 = 0;
ButtonstateRESET = 0;
}
// *** Cas du Bouton 2 ***
Buttonstate2 = digitalRead(ButtonPin2);
if (Buttonstate2 == HIGH) // Si le bouton 2 est activé
{
digitalWrite(LedPin2, HIGH); // Allumer la led du bouton 2
digitalWrite(BUZZER, HIGH);
delay(1000);
digitalWrite(BUZZER, LOW);
while (ButtonstateRESET != HIGH)
{
ButtonstateRESET = digitalRead(ButtonPinRESET);
}
digitalWrite(LedPin2, LOW); // Eteindre la led du bouton 2
Buttonstate2 = 0;
ButtonstateRESET = 0;
}
// *** Cas du bouton 3 ***
Buttonstate3 = digitalRead(ButtonPin3);
if (Buttonstate3 == HIGH) // Si le bouton 3 est activé
{
digitalWrite(LedPin3, HIGH); // Allumer la led du bouton 3
digitalWrite(BUZZER, HIGH);
delay(1000);
digitalWrite(BUZZER, LOW);
while (ButtonstateRESET != HIGH)
{
ButtonstateRESET = digitalRead(ButtonPinRESET);
}
digitalWrite(LedPin3, LOW); // Eteindre la led du bouton 3
Buttonstate3 = 0;
ButtonstateRESET = 0;
}
// *** Cas du bouton 4 ***
Buttonstate4 = digitalRead(ButtonPin4);
if (Buttonstate4 == HIGH) // Si le bouton 4 est activé
{
digitalWrite(LedPin4, HIGH); // Allumer la led du bouton 4
digitalWrite(BUZZER, HIGH);
delay(1000);
digitalWrite(BUZZER, LOW);
while (ButtonstateRESET != HIGH)
{
ButtonstateRESET = digitalRead(ButtonPinRESET);
}
digitalWrite(LedPin4, LOW); // Eteindre la led du bouton 4
Buttonstate4 = 0;
ButtonstateRESET = 0;
}
}