// STM32 Nucleo-C031C6 I2C Example
// Simulation: https://wokwi.com/projects/365421666018061313
#include "LiquidCrystal_I2C.h"
#include <Keypad.h>
#include <Stepper.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { A1, A2, A3, A4 };
uint8_t rowPins[ROWS] = { 3, 4, 5, 6 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int stepsPerRevolution = 360;
Stepper myStepper(stepsPerRevolution, 10, 11, 12, 13);
const int length = 4;
char password[] = {'1', '2', '3', '4'};
char printedpw[length];
int count = 0;
bool same = true;
void setup() {
Serial.begin(115200);
Serial.println("Hello, STM32!");
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("pls enter");
lcd.setCursor(0,1);
lcd.print("password :");
myStepper.setSpeed(60);
}
void display() {
lcd.clear();
if(same) {
lcd.setCursor(0,0);
lcd.print("successfully");
lcd.setCursor(0,1);
lcd.print("accessed");
}
else {
lcd.setCursor(0,0);
lcd.print("password");
lcd.setCursor(0,1);
lcd.print("incorrect");
}
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
if (key >= '0' && key <= '9') {
printedpw[count] = key;
lcd.print(key);
count++;
}
else if (key == '#') {
if (count == length) {
for (int i = 0; i < length; i++) {
if (password[i] != printedpw[i]) {
same = false;
break;
}
}
}
else same = false;
display();
count = 0;
}
}
}