#include <LiquidCrystal.h>
const int ledredPin = 9; // พินสีแดงพร้อม ~ const int ledbluepin = 10; // pin สีฟ้าที่มี ~ const int ledgreenpin = 11; // pin สีเขียวกับ ~
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 buttonless = 12; // pushbutton pin const int buttonmore = 13; // pushbutton pin
int buttonStok; int buttonstatemore; int buttonstateless;
const int photosensorpinfirst = 0; // อินพุตอินพุต pin const int int photosensorpinsecond = 1; // pin อินพุตอะนาล็อก
int lightlevelfirst; int lightlevelsecond;
เวลาเริ่มต้นที่ไม่ได้ลงชื่อ timepaused ยาวที่ไม่ได้ลงชื่อ = 0; timepassed ยาวที่ไม่ได้ลงชื่อ; ตารางเวลายาวที่ไม่ได้ลงชื่อ Timetemptwo ที่ไม่ได้ลงนาม bool ispaused = false;
bool isrunning = false; bool firstrun = true; จำนวน int ofpeople = 1; const char blank [17] = {""};
โมฆะการตั้งค่า () {// การตั้งค่า LCD colums/rows lcd.begin (16, 2); LCD.print ("ยินดีต้อนรับ"); // pushbuttons pin inputs pinmode (buttonok, input); pinmode (buttonmore, อินพุต); pinmode (ไม่มีปุ่ม, อินพุต);
// LED PIN OUTPUTS PINMODE (LEDREDPIN, เอาต์พุต); pinmode (ledbluepin, เอาต์พุต); pinmode (ledgreenpin, เอาต์พุต);
-
เป็นโมฆะลูป () {sensorreadings ();
if (buttonStok == สูง && firstrun) {isrunning = true; } ถ้า (isRunning) {modeSelection ();
-
DisplaySwitch (1); if (buttonStok == สูง &&! isrunning) {theend (); -
-
โมฆะ theend () {timepassed = millis () -timestart -timepaused; timetempone = millis ()-timestart; TimetEmptwo = timepassed/timetempone; TimetEmptwo *= 100; DisplaySwitch (2);
if (timetEmptWo <= 40) {DigitalWrite (LEDREDPIN, สูง);
} if (timetemptwo> 40 && timetEmptWo <70) {digitalWrite (ledbluepin, สูง);
} if (timetemptwo> = 70) {digitalWrite (ledGreenpin, สูง);
}} void sensorreadings () {buttonstateok = digitalRead (buttonok); buttonStateMore = digitalRead (buttonmore); ButtonStateless = DigitalRead (ไม่มีปุ่ม); lightlevelfirst = analogread (photosensorpinfirst); LightlevelSecond = analogread (photosensorpinsecond); -
Void Checklight () {ถ้า (Lightlevelfirst> = 800 &&! ispaused) {pauseevent (ispaused);
isPaused = true;
} else {if (lightlevelfirst <800) {pauseevent (ispaused); ispaused = false; -
} if (LightlevelSecond> = 800 &&! ispaused) {pauseevent (ispaused);
isPaused = true;
} else {ถ้า (LightlevelSecond <800) {PauseEvent (ispaused); ispaused = false; -
}} เป็นโมฆะหยุดชั่วคราว (bool ispaused) {ถ้า (ispaused) {timetemptwo = millis ();
timePaused += timeTempTwo-timeTempOne;
} else {timetempone = millis (); -
-
โมฆะ displayswitch (โหมด int) {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 ()-Timestart); 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, สูง); ความล่าช้า (100); DigitalWrite (LedGreenpin, สูง); ความล่าช้า (100); DigitalWrite (ledbluepin, สูง); ความล่าช้า (100); DigitalWrite (LEDREDPIN, ต่ำ); ความล่าช้า (100); DigitalWrite (LedGreenpin, ต่ำ); ความล่าช้า (100); DigitalWrite (LedBluepin, ต่ำ);
-
โมเดลโมดูลการเลือก () {
if(firstRun)
{
lightShow();
firstRun= false;
}
ทำ {displayswitch (0); if (buttonStateMore == สูง && numberOfPeople <7) {numberOfPeople ++; -
if(buttonStateLess == HIGH && numberOfPeople>1)
{
numberOfPeople--;
}
if(buttonStateOk == HIGH)
{
isRunning=false;
timeStart = millis();
}
} ในขณะที่ (isrunning);
-