Question
void setup() { lcd.init(); // initialize the lcd lcd.backlight(); pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); Serial.begin(9600); } void loop(){ lcd.setCursor(0,0); lcd.print(Enter Password:); digitalWrite(redLED, HIGH); //digitalWrite(greenLED,HIGH); char keyPress
void setup() { lcd.init(); // initialize the lcd lcd.backlight(); pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); Serial.begin(9600); }
void loop(){ lcd.setCursor(0,0); lcd.print("Enter Password:"); digitalWrite(redLED, HIGH); //digitalWrite(greenLED,HIGH); char keyPress = keypad.getKey(); if (keyPress != NO_KEY){ Serial.println(keyPress); } if (keyPress){ holder[holder_count] = keyPress; lcd.setCursor(holder_count, 1); lcd.print(holder[holder_count]); holder_count++; } if (holder_count ==password_length -1){ lcd.clear();
if (!strcmp(holder, correctPassword)) { lcd.print("Alarm Deactivated"); digitalWrite(redLED, LOW); //delay(3000); Serial.println("Alarm Deactivated"); digitalWrite(greenLED, HIGH); delay(2000);//time for how long the security alarm is deactivated before user alert digitalWrite(redLED,HIGH); digitalWrite(greenLED,LOW); if (wrong_password >0){ wrong_password = 0; } } else { lcd.print("Incorrect Password"); Serial.println("Incorrect Password"); wrong_password++; wrong_pw(); delay(2000); }
lcd.clear(); clearholder(); erase_wrong(); } }
void wrong_pw(){ while (wrong_password >= 2){ lcd.setCursor(0,3); lcd.print("Must Unlock With Key"); if pushButton ==High{
break;
} } }
void erase_wrong(){ if (wrong_password >=2) { wrong_password=0; } }
void clearholder() { while (holder_count != 0) { holder[holder_count--]= 0; } }
This is for Arduino. I am trying to break out of the while loop in the wrong_pw function using the if statement with the buttonState = HIGH, but this will not work. I really want the (!strcmp(holder, correctPassword)) to be
(!strcmp(holder, correctPassword)) || buttonState == HIGH, but this wont work either near the top of the loop. How can I exit that while loop in the wrong_pw function with a push button press?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started