Hi folks! ![]()
At first I wish You all a happy new year!
I have a project with 4x4 keypad and OLED. I'm tried to create password project. Everything works fine, but I have one issue. I have a question how to move pressed numbers on OLED I2C display in to my code?
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Keypad.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
#define SCREEN_ADDRESS 0x3C
#define passwordLengt 5
char data[passwordLengt];
char master[passwordLengt] = {"1234"};
byte dataCount = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9};
byte colPins[COLS] = {2, 3, 4, 5};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup()
{
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// display.display();
// delay(2000); // Pause for 2 seconds
display.clearDisplay();
Serial.begin(9600);
}
//void loop()
//{
// char customKey = customKeypad.getKey();
//
// if (customKey) {
// Serial.println(customKey);
// display.clearDisplay();
// display.setTextSize(2);
// display.setTextColor(WHITE);
// display.setCursor(0, 0);
// display.println(customKey);
// display.display();
//
// }
//}
void loop()
{
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Password:");
display.display();
customKey = customKeypad.getKey();
if (customKey) {
Serial.println(customKey);
data[dataCount] = customKey;
display.setCursor(0, 30);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(data[dataCount]);
display.display();
dataCount++;
}
if (dataCount == passwordLengt - 1) {
display.clearDisplay();
if (!strcmp(data, master)) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.println("Correct!");
display.display();
delay(3000);
}
else
{
display.setTextSize(2);
display.setTextColor(WHITE);
display.println("Incorrect!");
display.display();
delay(3000);
}
display.clearDisplay();
clearData();
}
}
void clearData() {
while (dataCount != 0) {
data[dataCount--] = 0;
}
return;
}