#include <LiquidCrystal.h>
const int ledredpin = 9; // ~ const int ledbluepin = 10; // red 컬러 핀 ~ const int ledgreenpin = 11; // ~ // 녹색 핀 ~ ~
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 액체 결정 LCD (RS, EN, D4, D5, D6, D7);
const int buttonok = 8; // pushbutton pin const int buttonless = 12; // pushbutton 핀 int buttonmore = 13; // pushbutton 핀
int buttonstateok; int buttonstatemore; int buttonstationseless;
const int phorsensorpinfirst = 0; // 아날로그 입력 핀 const int phortensorpinsecond = 1; // 아날로그 입력 핀
int lightlevelfirst; int lightlevelsecond;
서명되지 않은 긴 타임 스타트; 서명되지 않은 긴 시점 = 0; 서명되지 않은 긴 시계; 서명되지 않은 긴 TimetemPone; 서명되지 않은 긴 시간정제; bool ispaud = false;
bool isrunning = 거짓; bool firstrun = true; int numberofpeople = 1; const char blank [17] = { ""};
void setup () {// lcd setup colums/rows lcd.begin (16, 2); lcd.print ( "환영"); // pushbuttons 핀 입력 PinMode (ButtonOk, Input); PINMODE (ButtonMore, 입력); PINMODE (버튼리스, 입력);
// LED 핀 출력 PINMODE (LEDREDPIN, OUTPUT); PINMODE (LEDBLUEPIN, 출력); PINMODE (LEDGREENPIN, 출력);
}
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; timetemptwo = timepassed/timetempone; timetemptwo *= 100; 디스플레이 스위치 (2);
if (timetemptwo <= 40) {DigitalWrite (ledredpin, high);
} if (timetemptwo> 40 && timetemptwo <70) {DigitalWrite (LEDBLUEPIN, HIGH);
} if (timetemptwo> = 70) {DigitalWrite (LEDGREENPIN, HIGH);
}} void sensorreadings () {buttonstateok = digitalread (buttonok); ButtonStatemore = DigitalRead (ButtonMore); ButtonStateless = DigitalRead (ButtonLess); lightlevelfirst = analogread (photosensorpinfirst); lightlevelsecond = analogread (Photosensorpinsecond); }
void checklight () {if (lightlevelfirst> = 800 &&! ispaused) {pauseevent (ispaused);
isPaused = true;
} else {if (lightlevelfirst <800) {pauseevent (ispaused); ISPAUSED = FALSE; }
} if (lightlevelsecond> = 800 &&! ispaused) {pauseevent (ispaud);
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 (int mode) {char temp [] = ""; 스위치 (모드) {case 0 :
LCD.SetCursor (0,0); //lcd.print(Blank); lcd.print ( "플레이어 번호 :");
LCD.SetCursor (0,1); // lcd.print (blank); lcd.print (numberofpeople); lcd.display (); 부서지다;
case 1:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Time Passed:");
lcd.setCursor(0,1);
// lcd.print (blank); lcd.print (millis ()-Timestart); lcd.display (); 부서지다;
case 2:
lcd.setCursor(0,0);
//lcd.print(blank);
lcd.print("Success Rate:");
lcd.setCursor(0,1);
// lcd.print (blank); lcd.print (TimePassed); lcd.display (); 부서지다;
default:
lcd.setCursor(0,0);
// lcd.print (blank); LCD.SetCursor (0,1); // lcd.print (blank); lcd.display (); }
}
void lightshow () {DigitalWrite (ledredpin, high); 지연 (100); DigitalWrite (Ledgreenpin, High); 지연 (100); DigitalWrite (Ledbluepin, High); 지연 (100); DigitalWrite (LedRedpin, Low); 지연 (100); DigitalWrite (LEDGREENPIN, LOW); 지연 (100); DigitalWrite (LEDBLUEPIN, LOW);
}
void modeSelection () {
if(firstRun)
{
lightShow();
firstRun= false;
}
do {displayswitch (0); if (buttonstatemore == high && numberofpeople <7) {numberofpeople ++; }
if(buttonStateLess == HIGH && numberOfPeople>1)
{
numberOfPeople--;
}
if(buttonStateOk == HIGH)
{
isRunning=false;
timeStart = millis();
}
} while (isrunning);
}