#include <liquidcrystal.h>
const int ledRedpin = 9; // broche de couleur rouge avec ~ const int ledBluepin = 10; // broche de couleur bleue avec ~ const int lndgreenpin = 11; // broche de couleur verte avec ~
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LCD liquide (Rs, EN, D4, D5, D6, D7);
const int Buttonok = 8; // Pushbutton Pin const int boutonless = 12; // broche-poussoir const int boutonnage = 13; // broche de bouton-poussoir
int ButtonstateOK; int ButtonstateMore; Int Buttonstateless;
const int photosensorpinfirst = 0; // broche d'entrée analogique const int photosensorpinsecond = 1; // broche d'entrée analogique
int LightleVelfirst; int LightLevelSecond;
Timestart long non signé; Timepauté long non signé = 0; un long terme non signé; chronomètre long non signé; Long TimeMetemptwo, long non signé, non signé; bool ispaused = false;
bool isrunning = false; bool firstrun = true; int numberOfPeople = 1; const char blanc [17] = {""};
void setup () {// LCD SETUP COLUMS / ROWS LCD.BEGIN (16, 2); LCD.print ("Bienvenue"); // les entrées de broches de bouton-poussoir PinMode (Buttonok, entrée); PinMode (Buttonmore, entrée); PinMode (sans bouton, entrée);
// PIN LED Sorties PinMode (LEDDRedPin, sortie); pinmode (ledBluepin, sortie); PinMode (LedGreenPin, sortie);
}
void loop () {sensorReadings ();
if (ButtonStateOK == High && firstrun) {Isrunning = true; } if (Isrunning) {modeSelection ();
}
DisplaySwitch (1); if (ButtonStateOK == High &&! Isrunning) {theend (); }
}
void theend () {timePassed = Millis () - timeStart -TimePaused; TimeTempone = Millis () - TimeStart; TimeMetEmptwo = timepassée / timeTempone; TimeMetEmptwo * = 100; DisplaySwitch (2);
if (TimeMetEmptwo <= 40) {DigitalWrite (LeDredPin, High);
} if (TimeMetEmptwo> 40 && timeMetEmptwo <70) {DigitalWrite (ledBluepin, High);
} if (TimeMetEmptwo> = 70) {DigitalWrite (LedGreenPin, High);
}} void SensorReadings () {ButtonStateOK = DigitalRead (Buttonok); ButtonStateMore = DigitalRead (Buttonmore); ButtonStateless = DigitalRead (Buttonless); LightLeVelFirst = analograad (PhotosSenSorpinFirst); LightLevelSecond = Analogread (PhotosSenSorpinDeCon); }
VOID CHECKLIGHT () {if (LightLeVelfirst> = 800 &&! Ispaused) {PauseEvent (Ispaused);
isPaused = true;
} else {if (LightLeVelfirst <800) {PauSeEvent (Ispaused); ispaused = false; }
} if (LightLevelSecond> = 800 &&! ISPAUSED) {PauSEEvent (Ispaused);
isPaused = true;
} else {if (LightLevelSecond <800) {PauSeEvent (Ispaused); ispaused = false; }
}} void PauseEvent (bool ispaused) {if (ispaused) {timeTemptwo = Millis ();
timePaused += timeTempTwo-timeTempOne;
} else {timeTempone = Millis (); }
}
void DisplaySwitch (mode int) {char temp [] = ""; commutateur (mode) {cas 0:
lcd.setCursor (0,0); //lcd.print(blank); LCD.print ("Numéro de joueur:");
lcd.setCursor (0,1); // LCD.print (vierge); LCD.print (NumberOfPeople); lcd.display (); casser;
case 1:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Time Passed:");
lcd.setCursor(0,1);
// LCD.print (vierge); LCD.print (Millis () - TimeStart); lcd.display (); casser;
case 2:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Success Rate:");
lcd.setCursor(0,1);
// LCD.print (vierge); LCD.Print (TimePassed); lcd.display (); casser;
default:
lcd.setCursor(0,0);
// LCD.print (vierge); lcd.setCursor (0,1); // LCD.print (vierge); lcd.display (); }
}
void LightShow () {DigitalWrite (LeDredPin, High); retard (100); DigitalWrite (LedgreenPin, High); retard (100); DigitalWrite (LEDBLUEPIN, HIGH); retard (100); DigitalWrite (LeDredPin, Low); retard (100); DigitalWrite (LedgreenPin, Low); retard (100); DigitalWrite (LEDBLUEPIN, LOW);
}
void modeselelection () {
if(firstRun)
{
lightShow();
firstRun= false;
}
do {displaySwitch (0); if (ButtonStateMore == High && nombreOfPeople <7) {NumberOfPeople ++; }
if(buttonStateLess == HIGH && numberOfPeople>1)
{
numberOfPeople--;
}
if(buttonStateOk == HIGH)
{
isRunning=false;
timeStart = millis();
}
} while (Isrunning);
}