Single character keypad lock programming question

Hi guys, For my project I'm required to make a 4x3 keypad lock with a single digit as the password. For time sake I will quickly explain the guidelines. My password must be 4, and if 4 is pressed a green LED must blink twice and then remain on until the * key is pressed which is meant to reset the lock. If key 5, or 6(2 other keys in the row) are pressed a red led must flash on and off with a 1Hz frequency until the lock is once again reset with the * key. My problem I'm having is getting the program/lock to reset when the red LED is flashing. I have very limited knowledge with programming as I only have a first year university c++ course as experience. My code attached.

I think the problem is I am using a while(1) loop to keep the red LED flashing and I cannot get the loop to break, I've done a little research and found a switch function but I'm not sure how to utilise it. Any help will be appreciated..

void loop()
{
  
  char key = keypad.getKey();
  if (key == '*')
    {
      position = 0;
      digitalWrite(rpin, LOW);
      digitalWrite(gpin, LOW);
    }
    
   if(key == '5' || key == '6')
   {
    LockedPosition(true);
    if(key == '*');
    {
      position = 0;
      digitalWrite(rpin, LOW);
      digitalWrite(gpin, LOW);
    }
   }

  if (key == password[position])
    {
      position ++;
    }
    
  if (position == 1)
    {
      LockedPosition(false);
    }
    
  delay(100);
}

void LockedPosition(int locked)
 {
  if (locked)
    {
      while(1){
      digitalWrite(rpin, HIGH);
      delay(1000);
      digitalWrite(rpin, LOW);
      delay(1000);
      digitalWrite(gpin, LOW);
      }
    }
  else
    {
      digitalWrite(rpin, LOW);
      digitalWrite(gpin, HIGH);
      delay(100);
      digitalWrite(gpin, LOW);
      delay(100);
      digitalWrite(gpin, HIGH);
    }
}

Keypad.ino (1.3 KB)

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:
Is this a school project?

I see that the OP has only 1 post as I write this. But I read an almost identical question in this other Thread

I wonder if the two are friends and could pool their resources?

...R