This project is to get a button turn a light off for ten seconds and then turn back on after that ten seconds elapsed, and then have my keypad do the same after entering in the password, but the problem is that when I do run the program, The LCD turns on, says the beginning message, then the LED turns on and gives the LCD a green screen of death. heres my code,
int buttonState = 0;
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Key.h>
LiquidCrystal lcd(13,12,5,4,3,2);
const byte ROWS = 4;
const byte COLS = 4;
int lcdRow = 0;
char keys[ROWS][COLS]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
byte rowPins[ROWS]={A0,A1,A2,A3};
byte colsPins[COLS]={A4,A5,11,10};
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colsPins,ROWS,COLS);
String password;
void setup()
{
pinMode(7, INPUT);
pinMode(9, OUTPUT);
/////////////////////////////////////////////////////////////////////////
pinMode(2, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.print("Enter Password: ");
delay(1000);
lcd.clear();
}
void loop()
{
buttonState = digitalRead(7);
if (buttonState == LOW) {
digitalWrite(9, HIGH);
} else {
digitalWrite(9, LOW);
delay(10000); // Wait for 10000 millisecond(s)
////////////////////////////////////////////////////////////////////////////////////////////////
char key = keypad.getKey();
if (key){
lcd.print(key);
lcd.setCursor(++lcdRow,0);
password = password+key;
if (key=='A'){
lcd.clear();
lcd.print("Checking Password");
lcd.setCursor(0,1);
lcd.print(password);
delay(1000);
if (password=="111A"){
lcd.clear();
lcd.print("Accepted");
delay (1000);
lcd.clear();
password = "";
}
else {
lcd.clear();
lcd.print("Denied");
}
}
if (key=='C'){
lcd.print("Clearing...");
delay(1000);
lcd.clear();
password = "";
}
}
}
}
3 posts - 2 participants