combine numbers or / and letters with a matrix 4X4 keypad

Using arduino uno!!!

i made my own password thing with a keypad 4x4

but don’t know how to do this:

changepass:
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
Serial.println("");
Serial.print("oude code: ");
key12=keypad.waitForKey();
if(key12 == pass[0])
{
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
{
z=1;
Serial.print("*");
goto Aa;

}
}
else
{
goto dump;
}
Aa:
key22=keypad.waitForKey();
if(key22 == pass[1])
{
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
{
z=2;
Serial.print("*");
goto Bb;
}
}
else
{
goto dump;
}
Bb:
key32=keypad.waitForKey();
if(key32 == pass[2])
{
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
{
z=3;
Serial.print("*");
goto Cc;
}
}
else
{
goto dump;
}
Cc:
key42=keypad.waitForKey();
if(key42 == pass[3])
{
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
{
z=4;
Serial.print("*");
goto Dd;
}
}
else
{
goto dump;
}
Dd:
key52=keypad.waitForKey();
if(key52 == pass[4])
{
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
{
z=5;
Serial.print("*");
goto Ee;
}
}
else
{
goto dump;
}
Ee:
key62=keypad.waitForKey();
if(key62 == pass[5])
{
digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
{
z=6;
Serial.print("*");
goto oldcode;
}
}
else
{
goto dump;
}
oldcode:
chang=0;
Serial.println("");
Serial.print("nieuwe code: ");
goto pop;
pop:
if (chang==6)
{
  
}
else
{
  char button = keypad.waitForKey();
  if (button) {
    chang++;
    if(chang==1)
    {
    key13=button;
    Serial.print("*");
    digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
    goto pop;
    }
    else
    {
      if(chang==2)
    {
    key23=button;
    Serial.print("*");
    digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
    goto pop;
    }
    else
    {
      if(chang==3)
    {
    key33=button;
    Serial.print("*");
    digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
    goto pop;
    }
    else
    {
      if(chang==4)
    {
    key43=button;
    Serial.print("*");
    digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
    goto pop;
    }
    else
    {
      if(chang==5)
    {
    key53=button;
    Serial.print("*");
    digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
    goto pop;
    }
    else
    {
      if(chang==6)
    {
    key63=button;
    Serial.print("*");
    digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
    goto again;
    
    }
    
      
    }
    }
    }
    }
    }
    }
}
 again://again do the new password
 digitalWrite(ledPin2,HIGH);
delay(100);
digitalWrite(ledPin2,LOW);
//new code will save here:
//what i mean is this i just did the new password
//in the keys that end with 3 key13, key23 etc.
//so i want it like change newpass to key13+key23+key33 etc.

 Serial.println(); // and then change 'pass' to it!
 //so please help me thanks !!!

i just want to combine total of 6 numbers and letters in one but it don’t works please help
(it need to works with all combinations that can!!!)
thank you all!!! :smiley: :smiley: :smiley:

the things that it need to do are:
save the code don’t need to be saved if i restart it
the pass need to change to that
need to works with every code that can

-can’t type the whole code-

just use other variables i will change it!!

goto pop;
pop:

I'm out. Remove all the goto's and I'll look at it.

From the Arduino documentation on goto:

Notes and Warnings

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

Now rewrite it without using goto. :)

i just am new to arduino and i just made from a copied code my own and learn from the code so i am not that good
and don’t know why i can’t do ‘goto’

Notes and Warnings

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged.

"Keypad password" is a popular project for Arduino. There are much better examples of code on line for you to study and use.

Avoid any examples that use goto.

chickenprogram: i just am new to arduino and i just made from a copied code my own and learn from the code so i am not that good and don't know why i can't do 'goto'

Please, post complete codes of your sketch. Also post (a hand drawn picture would be okay) the schematic for the hardware that you are using in your project.

Using loops instead of repeating code over and over:

#include <Keypad.h>


const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

const byte ledPin2 = LED_BUILTIN;
char pass[] = "123456"; // Default password

// Return 'true' if the password is entered correctly.
bool EnterPassword()
{
  for (int index = 0; index < 6; index++)
  {
    if (keypad.waitForKey() == pass[index])
    {
      // This key matches
      digitalWrite(ledPin2, HIGH);
      delay(100);
      digitalWrite(ledPin2, LOW);
      Serial.print("*");
    }
    else
    {
      // NO MATCH
      return false;  // Password doesn't match
    }
  }
  return true; // All six keys matched
}




void SetNewPassword()
{
  char oldPassword[6];


  // Make a copy of the old password
  for (int index = 0; index < 6; index++)
  {
    oldPassword[index] = pass[index];
  }


  Serial.println("");
  Serial.print("nieuwe code: ");
  for (int index = 0; index < 6; index++)
  {
    pass[index] = keypad.waitForKey();
    // This key matches
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    Serial.print("*");
  }


  // See if they can enter the same password again
  if (EnterPassword())
    return;  // Matched the new password!
  else
  {
    // Failed to enter the same password twice.  Restore the old password.
    for (int index = 0; index < 6; index++)
    {
      pass[index] = oldPassword[index];
    }
  }
}


void setup()
{
  Serial.begin(115200);
  pinMode(ledPin2, OUTPUT);
}


void loop()
{
}

thank you i will try that

Personally I would wait until all 6 characters had been entered before returning true or false. That way the user will not know which character is wrong

UKHeliBob: Personally I would wait until all 6 characters had been entered before returning true or false. That way the user will not know which character is wrong

Feel free to show your code. :)

UKHeliBob:
Personally I would wait until all 6 characters had been entered before returning true or false. That way the user will not know which character is wrong

// Return 'true' if the password is entered correctly.
bool EnterPassword()
{
  bool match = true;
  for (int index = 0; index < 6; index++)
  {
    if (keypad.waitForKey() != pass[index])
    {
      // This key doesn't match
      match = false;
    }
    digitalWrite(ledPin2, HIGH);
    delay(100);
    digitalWrite(ledPin2, LOW);
    Serial.print("*");
  }
  return match; // Are all six keys matched?
}

johnwasser: Using loops instead of repeating code over and over:

I really don't understand how the following functions are being called upon when the loop() function is empty.

EnterPassword();
SetNewPassword();

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin2, OUTPUT);
}

void loop()
{
}

GolamMostafa: I really don't understand how the following functions are being called upon when the loop() function is empty.

The setup() and loop() are primarily to get the functions to compile without errors or warnings. The OPs code did not include a single complete function and the question did not describe any parts of the sketch that were not shown. Since the OP didn't provide a full sketch or specification, I saw no reason to implement parts of the sketch where I would have to guess what the OP intended. Feel free to expand the sketch to do what you think the OP wanted their sketch to do. :)