Keypad 3*4

Hello I'm using the keypad 3*4 a series of numbers and when key start (in keypad) print the code on Serial monitoring!? for example i want Print '123456' 1. first input number From Keypad (e.g. '123456') 2. after input number And Press *(star) show all number on Serial Monitoring! please Help Me....

please Help Me....

What is the problem? What code do you have so far?

Collecting keys, and storing the data in the next available position in an array is trivial.

NULL terminating the array is trivial.

Printing the array when something interesting happens is trivial.

when use this code only last number show on Serial monitoring!
i want show all number!

my code:

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
}

void loop(){
char key = keypad.getKey();

if (key == ‘*’){
Serial.print(key);
}
}

when use this code only last number show on Serial monitoring!
i want show all number!

So you need to collect the numbers…

const byte maxKeys = 10;
char storedKeys[maxKeys];
byte keyIndex = 0;
void loop()
{
  char key = keypad.getKey();
 
  if (key == '*')
  {
     Serial.print(storedKeys);
  }
  else
  {
     if(keyIndex < maxKeys)
     {
        storedKey[keyIndex++] = key; // Store the key
        storedKey[keyIndex] = '\0'; // NULL terminate the array
     }
  }
}

It was left as an exercise for the student to clear the array and reset the index at the appropriate (but as yet undefined) point in the code.

thanks , but uploading show this message: ‘storedKey’ was not declared in this scope

my code:

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const byte maxKeys = 10;
char storedKeys[maxKeys];
byte keyIndex = 0;
void setup(){
Serial.begin(9600);
}

void loop()
{
char key = keypad.getKey();

if (key == ‘*’)
{
Serial.print(storedKeys);
}
else
{
if(keyIndex < maxKeys)
{
storedKey[keyIndex++] = key; // Store the key
storedKey[keyIndex] = ‘\0’; // NULL terminate the array
}
}
}

These were wrong:

        storedKey[keyIndex++] = key; // Store the key
        storedKey[keyIndex] = '\0'; // NULL terminate the array

They should be:

        storedKeys[keyIndex++] = key; // Store the key
        storedKeys[keyIndex] = '\0'; // NULL terminate the array

this code uploading successful!
but open the Serial Monitor And push the button e.g. 123456 And press the ‘*’ not show the number on Serial Monitoring!

my code:

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’}
};
byte rowPins[ROWS] = {5, 4, 3, 2};
byte colPins[COLS] = {8, 7, 6};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const byte maxKeys = 10;
char storedKeys[maxKeys];
byte keyIndex = 0;
void setup(){
Serial.begin(9600);
}

void loop()
{
char key = keypad.getKey();
if (key == ‘*’)
{
Serial.print(storedKeys);
}
else
{
if(keyIndex < maxKeys)
{
storedKeys[keyIndex++] = key; // Store the key
storedKeys[keyIndex] = ‘\0’; // NULL terminate the array
}
}
}

else

should be:

else if(key != NO_KEY)

thanks very much