#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Keypad setup
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Clear button setup
const int clearButtonPin = 10; // Pin connected to the clear button
void setup() {
Serial.begin(9600);
pinMode(clearButtonPin, INPUT_PULLUP); // Set the clear button pin as input with internal pull-up resistor
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(SSD1306_WHITE);
}
void loop() {
char key = keypad.getKey();
if (key) {
display.clearDisplay();
display.setCursor(0, 10);
display.print("Key : ");
display.print(key);
display.display();
delay(500);
}
// Check if the clear button is pressed
if (digitalRead(clearButtonPin) == LOW) {
display.clearDisplay();
display.display();
delay(500); // Debounce delay
}
}
Red button = CLEAR