#include <caircrystal.h>
const int ledredpin = 9; // pin warna merah dengan ~ const int ledbluepin = 10; // pin warna biru dengan ~ const int ledgreenpin = 11; // pin warna hijau dengan ~
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; Liquidcrystal LCD (RS, EN, D4, D5, D6, D7);
const int buttonok = 8; // pushbutton pin const int buttonesless = 12; // pushbutton pin const int buttonmore = 13; // tekan tekan pin
int ButtonStateok; int buttonstatemore; int buttonseless;
const int fotosensorpinfirst = 0; // input analog pin const int fotosensorpinsecond = 1; // pin input analog
int lightlevelfirst; int lightlevelsecond;
timestart panjang yang tidak ditandatangani; Timepauss Long Unsigned = 0; tidak ditandatangani lama timepassed; jadwal panjang yang tidak ditandatangani; jadwal panjang yang tidak ditandatangani; bool ispaused = false;
bool isrunning = false; bool firstrun = true; int numberofpeople = 1; const char blank [17] = {""};
void setup () {// lcd setup colums/rows lcd.begin (16, 2); lcd.print ("selamat datang"); // input PIN PUTBUTTON PinMode (Buttonok, Input); pinmode (tombolMore, input); pinmode (tanpa tombol, input);
// output pin LED pinMode (LEDREDPIN, Output); pinmode (ledbluepin, output); pinmode (ledgreenpin, output);
}
void loop () {sensorreadings ();
if (buttonstateok == tinggi && firstrun) {isRunning = true; } if (isRunning) {ModeSelection ();
}
displayswitch (1); if (buttonstateok == tinggi &&! isRunning) {theEnd (); }
}
void theend () {timePassed = millis () -TimestArt -TimePauss; timeTempone = millis ()-timestArt; timeTemptWo = timePassed/timeMPone; jadwal *= 100; DisplaySwitch (2);
if (timeTemptWo <= 40) {DigitalWrite (LedRedpin, High);
} if (timeTemptWo> 40 && timeTemptWo <70) {DigitalWrite (ledbluepin, tinggi);
} if (timeTemptWo> = 70) {DigitalWrite (ledgreenpin, tinggi);
}} void sensorreadings () {ButtonStateok = DigitalRead (Buttonok); ButtonStatemore = DigitalRead (ButtonMore); ButtonSteleless = DigitalRead (Buttonless); lightlevelfirst = analogread (photosensorpinfirst); lightlevelsecond = analogread (photosensorpinsecond); }
void checklight () {if (lightlevelfirst> = 800 &&! isPaSe) {PAELEEvent (isPaSeused);
isPaused = true;
} else {if (lightlevelfirst <800) {PauseEvent (isPaSe); ispaused = false; }
} if (LightLevelSecond> = 800 &&! IsPaSe) {PauseEvent (isPaSeused);
isPaused = true;
} else {if (LightLevelSecond <800) {PauseEvent (isPaSeused); ispaused = false; }
}} void jualEvent (bool isPaSeused) {if (isPaSeused) {timeTemptWo = millis ();
timePaused += timeTempTwo-timeTempOne;
} else {timeTempone = millis (); }
}
void displayswitch (mode int) {char temp [] = ""; switch (mode) {case 0:
LCD.SetCursor (0,0); //lcd.print(blank); LCD.Print ("Nomor Pemain:");
LCD.SetCursor (0,1); // lcd.print (kosong); lcd.print (numberofpeople); lcd.display (); merusak;
case 1:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Time Passed:");
lcd.setCursor(0,1);
// lcd.print (kosong); lcd.print (millis ()-timestArt); lcd.display (); merusak;
case 2:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Success Rate:");
lcd.setCursor(0,1);
// lcd.print (kosong); lcd.print (timePassed); lcd.display (); merusak;
default:
lcd.setCursor(0,0);
// lcd.print (kosong); LCD.SetCursor (0,1); // lcd.print (kosong); lcd.display (); }
}
void lightshow () {DigitalWrite (LedRedpin, High); tunda (100); DigitalWrite (Ledgreenpin, High); tunda (100); DigitalWrite (Ledbluepin, High); tunda (100); DigitalWrite (Ledredpin, Low); tunda (100); DigitalWrite (Ledgreenpin, Low); tunda (100); DigitalWrite (Ledbluepin, Low);
}
void modeselection () {
if(firstRun)
{
lightShow();
firstRun= false;
}
do {displayswitch (0); if (buttonstatemore == tinggi && numberofpeople <7) {numberofpeople ++; }
if(buttonStateLess == HIGH && numberOfPeople>1)
{
numberOfPeople--;
}
if(buttonStateOk == HIGH)
{
isRunning=false;
timeStart = millis();
}
} while (isrunning);
}