I think this is a code issue

Hi,

This is doing my head in!

I am running this code;

OK so the While while loop is active and the timer counting down correctly, every time I press a key I want it to display the key pressed on the LCD.

The issue I am having is that when I press a button on the keypad it is only registering intermittently when I spam the keys.

The keypad seems to be working fine when out of this loop situation?

also PadGameTIme(gametime); is just calling a routine which displays the time on the LCD, I have another routine in my code which calls this and it is working fine, so I don’t think there is any issue in this routine

The variable interval is set to 1000 or 1 seconds, I have tried changing the interval to 2000 or 2 seocnds thinking it might have been a response issue but it makes no difference

while (gametime >0 && correctcode == 0)
  {
      currentMillis = millis();
      if(currentMillis - previousMillis > interval) 
         {
            // save the last time you blinked the LED 
            previousMillis = currentMillis;   
             gametime = gametime - 1;
             PadGameTIme(gametime);
   
            char key = keypad.getKey(); // read input from key pad
             if (key >= 48 && key <=57)
                {
                switch (bombcodeposition) //increases every time a key is pressed to change the location the key press is displayed on the LCD
                  {
                  case 0:
                     lcdP1.setCursor(11,0);
                     enteredcode1 = key;
                     lcdP1.print(key);
                     bombcodeposition = 1;
                     break;
                 case 1:
                     lcdP1.setCursor(12,0);
                     enteredcode2 = key;
                     lcdP1.print(key);
                     bombcodeposition = 2;
                     break;
                 case 2:
                     lcdP1.setCursor(13,0);
                     enteredcode3 = key;
                     lcdP1.print(key);
                     bombcodeposition = 3;
                     break;
                 case 3:
                     lcdP1.setCursor(14,0);
                     enteredcode4 = key;
                     lcdP1.print(key);
                     // check code procedure
                     comparecode();
                     lightcorrectLCDs();
                     bombcodeposition = 0;
                     break;
            }
          }

         }
}

Many thanks for any help

Dexter

You are only checking the keypad once a second. You probably want to check it all the time, even when a 1s interval is not reached.

My friend thank you very much, I could not see that for looking at it!

o7

Dexter