#include <LiquidCrystal_I2C.h>;
LiquidCrystal_I2C lcd(0x27,16,2);
int sensor = 2; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
int count=0;
unsigned long delayStart = 0;
bool delayRunning = false;
void setup() {
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial
lcd.init();
lcd.backlight();
delayStart = millis(); // start delay
delayRunning = true; // not finished yet
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) {
count=count+1;
delay(500);
}
else {
count=count;
delay(500);
}
lcd.setCursor(1,1);
//N(number of students)
lcd.print("N=");
lcd.print(count);
lcd.print("/30");
if (delayRunning && ((millis() - delayStart) >= 300000)) {
exit(0);
}
if (count>30){
exit(0);
}
}
//1000=1s 10000=10s 60000=1min 300000=5m