hi, i´m doing this big project, and i´m currently struggling with this part of the code.
what it should do:
when you press "C", user enters a number from a 4x4 keypad, which can be single or multiple digits.
what happens is that when you press a key, it gets added to the input_password consecutively, and when you press another, then those 2 numbers get added on consecutively (like, i press 2 and the input_password is 222222etc until i press 7, and then it´s 22222222272727272727, and so on)
this is the code:
#include <Keypad.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {6,7,8,9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
String input_password;
void setup(){
Serial.begin(9600);
input_password.reserve(32); // maximum input characters is 33, change if needed
}
void loop(){
char key = keypad.getKey();
if (key){
if(key == 'C') {
input_password = ""; // clear input password
Serial.println("Ingrese su ID: ");
CCgetId();
Serial.println(input_password);
}
}
}
int CCgetId(){
char key = keypad.getKey();
String input_password;
do{
key = keypad.getKey();
input_password += key; // append new character to input password string
Serial.print(input_password);
} while (key != '#');
}