I am working on a project which requires the user to press a key on the keypad when an interrupt is called. The interrupt is called by pressing a push button and the function that it executes requires the user to then press either 1,2,3,or 4 before proceeding to make the necessary computations.
The problem is that when I use keypad.waitForKey(), the program just stops executing.
Can anyone please help me figure this out.
Here is the code for the function
void addPassenger(){
if(digitalRead(3))
{
//When LED lights///user can choose option
digitalWrite(10,HIGH);
lcd.clear();
key = NO_KEY;
while(true){
key = keypad.waitForKey();
myDelay(100);
lcd.print(“?”);
if(key != NO_KEY)
break;
}
state = false;
switch(key){
case ‘2’:
if(!onBoard[1]){
onBoard[1] = true;
numberOnBoard++;
lcd.setCursor(0,1);
lcd.print(“Passenger 2 added”);
}
else
{
lcd.setCursor(0,1);
lcd.print(“Passenger already in”);
}
break;
case ‘3’:
if(!onBoard[2]){
onBoard[2] = true;
numberOnBoard++;
lcd.setCursor(0,1);
lcd.print(“Passenger 3 added”);
}
else
{
lcd.setCursor(0,1);
lcd.print(“Passenger already in”);
}
break;
case ‘4’:
if(!onBoard[3]){
onBoard[3] = true;
numberOnBoard++;
lcd.setCursor(0,1);
lcd.print(“Passenger 4 added”);
}
else
{
lcd.setCursor(0,1);
lcd.print(“Passenger already in”);
}
break;
}
}
else
digitalWrite(10,LOW);
}
N.B I placed an LED on pin 10 to indicate when the interrupt is called…it lights when I press the push button