#include <I2CKeyPad.h>
#include <Wire.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#define deltaTime(val) (millis()-val)
I2CKeyPad keyPad(0x38);
char keypad_layout[19] = "123A456B789C*0#DNF"; // N = NO_KEY, F = FAILED
// Just to avoid spamming
unsigned long lastKeyPress = 0;
unsigned long keyDelay = 200;
void keypadTask(void *pvParameters) {
for (;;) {
if (keyPad.isPressed() && deltaTime(lastKeyPress) > keyDelay) {
lastKeyPress = millis();
char ch = keyPad.getChar();
Serial.println("Pressed : " + String(ch));
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
void setup() {
Serial.begin(9600);
if (!keyPad.begin()) {
Serial.print("Cannot connect to I2C.\n");
while(1);
}
keyPad.loadKeyMap(keypad_layout);
xTaskCreatePinnedToCore(
keypadTask, // Function to implement the task
"keypadTask", // Name of the task
10000, // Stack size in words
NULL, // Task input parameter
1, // Priority of the task
NULL, // Task handle
0 // Core where the task should run
);
}
void loop() {
// Do nothing
}