/*
Forum: https://forum.arduino.cc/t/pull-up-down-or-give-up/1442473/58
Wokwi: https://wokwi.com/projects/463107114737143809
2026/05/04
ec2021
Created a keypad class that provides the following functions
* begin() prepares the row and col pins, disables hold function from deep sleep
* pressed() returns true if a button in the key matrix has been pressed, else false
* getKey() returns the last key that was registered
* getIndex() returns the index of the last key pressed, range [0 ... COLSxROWS] with 0 == No key pressed
* prepareDeepSleep() sets the row pins to OUTPUT LOW and holds the states of row and col pins during deep sleep
The row and col numbers and pins as well as the respective key characters are defined in myKeypad.h.
This has to be changed for a different layout.
(!) As GPIO14 is not available with the ESP32-C6 Dev Kit in Wokwi, GPIO13 is used instead of GPIO14.
*/
#include <Arduino.h>
#include "myKeypad.h"
myKeypad keypad;
// ---------------- SETUP ----------------
void setup() {
Serial.begin(115200);
keypad.begin();
}
// ---------------- LOOP ----------------
void loop() {
if (keypad.pressed()) {
handleKeyPress();
}
}
void handleKeyPress() {
Serial.print("KEY: ");
Serial.print(keypad.getKey());
Serial.print("\tIDX: ");
Serial.println(keypad.getIndex());
}