#include <liquidcrystal.h>
const int redredpin = 9 ؛ // دبوس اللون الأحمر مع ~ const int ledbluepin = 10 ؛ // دبوس اللون الأزرق مع ~ const int ledgreenpin = 11 ؛ // دبوس اللون الأخضر مع ~
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 button = 12 ؛ // pushbutton pin const int buttonmore = 13 ؛ // pushbutton pin
int buttonstateok ؛ int buttonstatemore ؛ int buttonstateless ؛
const int photoSensorpinFirst = 0 ؛ // دبوس الإدخال التناظرية const int photoSpinsecond = 1 ؛ // دبوس الإدخال التناظرية
int lightlevelfirst. int lightlevelsecond.
طابع زمني طويل غير موقّع ؛ TimePaused الطويل غير موقعة = 0 ؛ غير موقّع الطويل جدول زمني طويل غير موقّع ؛ غير موقّع منذ زمن طويل. bool ispaused = false ؛
Bool isrunning = false ؛ Bool Firstrun = True ؛ int numberofpeople = 1 ؛ const char blank [17] = {""} ؛
setup void () {// lcd setup colums/rows lcd.begin (16 ، 2) ؛ LCD.Print ("مرحبًا") ؛ // pushbuttons Pin Inports pinmode (buttonok ، input) ؛ pinmode (buttonmore ، input) ؛ pinmode (بدون زر ، إدخال) ؛
// مخرجات دبوس LED Pinmode (LeDredpin ، الإخراج) ؛ Pinmode (Ledbluepin ، الإخراج) ؛ pinmode (دخل الأشرار ، الإخراج) ؛
}
void loop () {sensorreadings () ؛
if (buttonStateok == High && firstrun) {iSrunning = true ؛ } if (iSrunning) {modeselection () ؛
}
shanswitch (1) ؛ if (buttonStateok == High &&! isrunning) {theend () ؛ }
}
void theend () {timePassed = millis () -mutestart -TimePaused ؛ timetempone = millis ()-MITESTART ؛ timetemptwo = timePassed/timetempone ؛ timetemptwo *= 100 ؛ shanswitch (2) ؛
if (timetemptwo <= 40) {digitalWrite (ledredpin ، high) ؛
} if (timetemptwo> 40 && timetemptwo <70) {digitalWrite (ledbluepin ، high) ؛
} if (timeTemptWo> = 70) {digitalWrite (degultgreenpin ، high) ؛
}} void sensorreadings () {buttonstateok = digitalRead (buttonok) ؛ buttonStateMore = DigitalRead (buttonmore) ؛ ButtonStateless = DigitalRead (بدون زر) ؛ lightlevelfirst = analogRead (phussensorpinfirst) ؛ Lightlevelsecond = analogread (pussensorpinsecond) ؛ }
مصباح chectly void () {if (lightlevelfirst> = 800 &&! isPaused) {pauseevent (isPaused) ؛
isPaused = true;
} آخر {if (lightlevelfirst <800) {pauseevent (isPaused) ؛ ispaused = false ؛ }
} if (lightlevelsecond> = 800 &&! isPaused) {pauseevent (isPaused) ؛
isPaused = true;
} آخر {if (lightlevelsecond <800) {pauseevent (isPaused) ؛ ispaused = false ؛ }
}} void pauseevent (bool isPaused) {if (isPaused) {timtemptwo = millis () ؛
timePaused += timeTempTwo-timeTempOne;
} آخر {timetempone = millis () ؛ }
}
void siredayswitch (int mode) {char temp [] = "" ؛ التبديل (الوضع) {الحالة 0:
LCD.SetCursor (0،0) ؛ //lcd.print(blank) ؛ LCD.Print ("رقم اللاعب:") ؛
LCD.SetCursor (0،1) ؛ // lcd.print (فارغ) ؛ LCD.PRINT (NumberOfPeople) ؛ lcd.display () ؛ استراحة؛
case 1:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Time Passed:");
lcd.setCursor(0,1);
// lcd.print (فارغ) ؛ LCD.PRINT (millis ()-MIDESTART) ؛ lcd.display () ؛ استراحة؛
case 2:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Success Rate:");
lcd.setCursor(0,1);
// lcd.print (فارغ) ؛ LCD.PRINT (timePassed) ؛ lcd.display () ؛ استراحة؛
default:
lcd.setCursor(0,0);
// lcd.print (فارغ) ؛ LCD.SetCursor (0،1) ؛ // lcd.print (فارغ) ؛ lcd.display () ؛ }
}
void lightshow () {digitalWrite (ledredpin ، high) ؛ التأخير (100) ؛ DigitalWrite (دخل الأشرطة ، عالية) ؛ التأخير (100) ؛ DigitalWrite (Ledbluepin ، High) ؛ التأخير (100) ؛ DigitalWrite (LEDREDPIN ، LOW) ؛ التأخير (100) ؛ DigitalWrite (دخل الأشرطة ، منخفضة) ؛ التأخير (100) ؛ DigitalWrite (ledbluepin ، low) ؛
}
void modeselection () {
if(firstRun)
{
lightShow();
firstRun= false;
}
do {sireayswitch (0) ؛ if (buttonStateMore == High && numberOfPeople <7) {numberOfPeople ++ ؛ }
if(buttonStateLess == HIGH && numberOfPeople>1)
{
numberOfPeople--;
}
if(buttonStateOk == HIGH)
{
isRunning=false;
timeStart = millis();
}
} بينما (isrunning) ؛
}