#include <Keypad.h>
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
int tiempo = 0; //
int velocidadPulsacion = 25; //tiempo pulsador accion 1, si se pulsa antes de terminar = accion2.
bool final = true; // NOs permite sacar 2 valores para dos acciones de un pulsador.
if (key == 'A')
{
final = false; // accion 1 del la KEY
for (int i = 0; i < velocidadPulsacion; i++) {
tiempo++;
Serial.print("Boton single shot: ");
//Serial.println(tiempo);
Serial.println(final);
if (keypad.getKey() == 'A') {
final = true; // accion 2 del la KEY
Serial.print("Boton double shot: ");
Serial.println(final);
break; // Salir del bucle for
}
}
tiempo = 0; // Resetea el contador
}
}