Need help regarding loop

Hi! Can anyone help me re my program? I am developing a program for a counter. But it has additional features in it; keypad for authorization (the device cannot allow a user to access without the proper passcode) and sms notifier. My concern is re the loop of my authorization. After I pressed on the correct pin, it grants access but it doesn’t allow me to count by pressing on the push buttons. It goes back to the top of the loop. I separated the counting procedure in a different function that i called after the access has been granted.

Here’s the code i made so far (see attached):

keypasstrial.ino (12 KB)

[code]int switchPin1 = 14; // choose the input pin (for a pushbutton)
int switchPin2 = 16; //push button
int switchPin3 = 20; //push button
int switchPin4 = 22; //push button
int switchPin5 = 15; //push button
int switchPin6 = 17; //done button
int switchPin7 = 21; //reset button

When you start numbering variables, it's time to start thinking arrays.

      String numb(keypass);
      if (numb.equals("B")){

That is the stupidest thing I've seen today.

if(keypass == 'B')

and quit pissing away resources on the stupid String class. Forget it even exists!

        if (passcode.equals(pin)){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Access Granted!");
          pass=true;
          passcode="";
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Start Counting!");
          counter();
        }//if passcode is correct close
        else{
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Access Denied!");
          lcd.setCursor(0,1);
          lcd.print("Try Again");
          pass=true;
          passcode="";
          delay(2000);
        }//access denied close

If the correct passcode is entered, pass is set to true. If the wrong passcode is entered, pass is set to true. Why?

  if (val1 == HIGH) { // check if the input is HIGH (button released)
    currentState1 = 1;
  }
  else {
    currentState1 = 0;
  }

As opposed to the far simpler:

   currentState1 = val;

?

counter() is a pretty useless name for the function. A good name has a noun and a verb, like digitalRead(). It is not at all clear what counter is supposed to do.[/code]

@PaulS -thanks man! i already made some changes to what you're referring to. But i'm just wondering if you can help me out re the loop? coz my program keeps on going back to the part where it asks "Enter Passcode:". I cannot go to the process of counting by pressing the push buttons i have. :(

I cannot go to the process of counting by pressing the push buttons i have.

Well, you could, if you separated the part about getting the passcode from the part that does stuff once the correct passcode has been entered.

Why do you collect the passcode in loop? That should be done in setup(), so loop() doesn't start until the correct passcode has been entered.

If you are going to do it in loop(), there needs to be some mechanism that allows something like a log out.

@PaulS -oohh i see. okay i transferred the passcode stuff in the setup() portion. but upon entering a wrong passcode, it still proceeds to loop(). How can i keep it asking if the entered passcode is incorrect?

okay i transferred the passcode stuff in the setup() portion.

We need to see the new code.