#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#define LEBAR 128
#define TINGGI 64
LiquidCrystal_I2C lcd(0x27, 16,2);
Adafruit_SSD1306 oled(LEBAR,TINGGI, &Wire, -1);
#define RED 26
#define GREEN 25
const int BARIS = 4;
const int KOLOM = 4;
char keys[BARIS][KOLOM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
};
// R1 = 23. R2 = 19, R3 = 18, R4 = 5
// C1 = 4. C2 = 2, C3 = 15, C4 = 13
byte rowPins[BARIS] = {23, 19, 18, 5};//connect to the row pinouts of the keypad
byte colPins[KOLOM] = {4, 2, 15, 13};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, BARIS, KOLOM);
char keyInput;
int number = 0;
int password = 98;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3c)){
Serial.println(F("Falied to start OLED"));
while(1);
}
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
delay(2000);
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.println("Hello world");
oled.display();
}
void loginLCD(){
keyInput = keypad.getKey();
lcd.setCursor(0,0);
lcd.print("Input pass: ");
switch(keyInput){
case '0' ... '9':
lcd.setCursor(0,1);
number = number * 10 + (keyInput - '0');
lcd.print(number);
break;
case '#':
if(number == password){
lcd.setCursor(0,1);
lcd.print("Password correct");
digitalWrite(GREEN, HIGH);
delay(2000);
digitalWrite(GREEN, LOW);
number = 0;
lcd.clear();
}else{
lcd.setCursor(0,1);
lcd.print("Password incorrect");
digitalWrite(RED, HIGH);
delay(2000);
digitalWrite(RED, LOW);
number = 0;
lcd.clear();
}
break;
case '*':
number = 0;
lcd.clear();
break;
}
}
void loop() {
keyInput = keypad.getKey();
if(keyInput){
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print("Press: ");
oled.println(keyInput);
oled.display();
delay(100);
}
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
keypad1:R1
keypad1:R2
keypad1:R3
keypad1:R4
keypad1:C1
keypad1:C2
keypad1:C3
keypad1:C4
lcd2:GND
lcd2:VCC
lcd2:SDA
lcd2:SCL
led1:A
led1:C
led2:A
led2:C
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA