#include <Wire.h>
#include<Adafruit_GFX.h>
#include<Adafruit_SSD1306.h>
#include <Keypad.h>
#define llayar 128
#define tlayar 64
Adafruit_SSD1306 oled(llayar, tlayar, &Wire, -1);
const byte baris =4;
const byte kolom=4;
char hexaKeys[baris][kolom] ={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[baris]={14,12,19,18};
byte colPins[kolom]={5,4,2,15};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, baris, kolom);
void setup() {
Serial.begin(9600);
// intialize ioled display with i2c address 0x3c//
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000);
oled.clearDisplay();
oled.setTextSize(1); //atur ukuran text
oled.setTextColor(WHITE); //atur warna text
oled.setCursor(0,10); //atur posisi text pd display
oled.println("ESP32 Keypad dengan OLED");
delay(2000);
oled.display();
oled.clearDisplay(); //menampilkan display oled
}
void loop() {
char customKey= customKeypad.getKey();
if(customKey){
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print("Press: ") ;
oled.print(customKey);
oled.display();
delay(100);
}
}
Loading
ssd1306
ssd1306