Also ich blick da nicht ganz durch.
Versuch mal den Sketch
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] =
{
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char idNum[4] = {0};
uint8_t id = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
getId();
}
void getId()
{
char key = keypad.getKey();
if (key)
{
Serial.println(key);
if (key != '#')
{
idNum[id] = key;
id++;
}
if (id == 3 || key == '#')
{
Serial.println(idNum);
id = 0;
memset(idNum, 0, sizeof(idNum));
}
}
}
Was soll der Code machen:
Ich willvon 1 bis 3 Zahlen eingeben.
Jede Zahl wird extra ausgegeben.
Wenn ich 3 Zahlen drin habe ODER ich die # drücke, dann werden die bisher aufgenommenen Zeichen ausgegeben.
Wenn das funktioniert, kannst Du daraus eine Funktion mit Rückgabe machen.