#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int gomb1 = 8;
int gomb2 = 9;
int gomb3 = 10;
int gomb4 = 11;
int jelszo[4] = {4, 3, 1, 2};
int beirt[4] = {0, 0, 0, 0};
int lenyomas = 0;
void setup() {
lcd.begin(16, 2);
pinMode(gomb1, INPUT);
pinMode(gomb2, INPUT);
pinMode(gomb3, INPUT);
pinMode(gomb4, INPUT);
lcd.print("4 JEGYU KOD: ");
}
void loop() {
int gomb1A = digitalRead(gomb1);
int gomb2A = digitalRead(gomb2);
int gomb3A = digitalRead(gomb3);
int gomb4A = digitalRead(gomb4);
if (gomb1A == HIGH && lenyomas < 4) {
beirt[lenyomas] = 1;
lcd.setCursor(lenyomas, 1);
lcd.print(beirt[lenyomas]);
lenyomas++;
delay(200);
}
if (gomb2A == HIGH && lenyomas < 4) {
beirt[lenyomas] = 2;
lcd.setCursor(lenyomas, 1);
lcd.print(beirt[lenyomas]);
lenyomas++;
delay(200);
}
if (gomb3A == HIGH && lenyomas < 4) {
beirt[lenyomas] = 3;
lcd.setCursor(lenyomas, 1);
lcd.print(beirt[lenyomas]);
lenyomas++;
delay(200);
}
if (gomb4A == HIGH && lenyomas < 4) {
beirt[lenyomas] = 4;
lcd.setCursor(lenyomas, 1);
lcd.print(beirt[lenyomas]);
lenyomas++;
delay(200);
}
if (lenyomas == 4) {
if (beirt[0] == jelszo[0] && beirt[1] == jelszo[1] && beirt[2] == jelszo[2] && beirt[3] == jelszo[3]) {
lcd.clear();
lcd.print("OK");
} else {
lcd.clear();
lcd.print("STOP");
}
delay(2000);
lenyomas = 0;
for (int i = 0; i < 4; i++) {
beirt[i] = 0;
}
lcd.clear();
lcd.print("4 JEGYU KOD:");
}
delay(100);
}