#include <Arduino.h>
#include <Keypad.h>
#include "U8glib.h"
#include <Wire.h>
#define SDA_PIN 8
#define SCL_PIN 9
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
#define LED 21
int progress = 0;
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] = { 39, 40, 41, 42 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 35, 36, 37, 38 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
#define MAX_QR_LENGTH 20
//-------------------------------------//
class ParkingSpace {
public:
ParkingSpace(int pin, int number) : pin(pin), number(number), occupied(false) {
pinMode(pin, INPUT_PULLUP); // Initialize limit switch pin
}
void check() {
bool currentState = digitalRead(pin) == LOW; // LOW when pressed
if (currentState != occupied) {
occupied = currentState;
Serial.print("Parking Space ");
Serial.print(number);
Serial.print(": ");
Serial.println(occupied ? "Occupied" : "Empty");
// Update LCD here or notify an LCDManager
}
}
bool isOccupied() const {
return occupied;
}
void setQRData(const String& data) {
qrData = data;
}
String getQRData() const {
return qrData;
}
int getNumber() const {
return number;
}
private:
int pin;
int number;
bool occupied;
String qrData;
};
//------------------------------------------------//
class QRScanner {
public:
// Update method to check for incoming serial data
String update();
// Method to handle the received command (can be overridden or modified)
virtual void handleCommand(String command);
private:
String commandBuffer; // Buffer to accumulate incoming data
};
// Update method to read serial data
String QRScanner::update() {
while (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
handleCommand(commandBuffer);
commandBuffer = ""; // Reset buffer after handling
} else if (c != '\r') {
commandBuffer += c; // Accumulate characters
}
}
return commandBuffer;
}
// Default command handler (can be overridden in derived classes)
void QRScanner::handleCommand(String command) {
// Implement default behavior or leave empty for subclasses to override
//dito ung ishoshow sa OLED
Serial.println("Received command: " + command);
}
QRScanner qrScanner;
ParkingSpace spaces[] = {
ParkingSpace(18, 1),
ParkingSpace(17, 2),
ParkingSpace(16, 3),
ParkingSpace(15, 4),
ParkingSpace(7, 5),
ParkingSpace(6, 6),
ParkingSpace(5, 7),
ParkingSpace(4, 8),
};
const String password = "1234"; // change your password here
String input_password;
void setup() {
pinMode(LED, OUTPUT);
Wire.begin(SDA_PIN, SCL_PIN);
Serial.begin(115200);
Serial.println("Data received from UART chip:");
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
}
void loop() {
// digitalWrite(LED, HIGH);
// delay(500);
// digitalWrite(LED, LOW);
// delay(500);
// while (Serial.available()) {
// Serial.print((char)Serial.read());
// }
String qrCode = qrScanner.update();
// If a complete QR code is received, process it
u8g.firstPage();
do {
u8g.drawStr(25, 50, "Progress Bar");
u8g.drawFrame(0, 10, 128, 20);
u8g.drawBox(10, 15, progress, 10);
} while ( u8g.nextPage() );
if (progress < 108) {
progress++;
} else {
progress = 0;
}
char key = keypad.getKey();
if (key){
Serial.println(key);
if(key == '*') {
input_password = ""; // clear input password
} else if(key == '#') {
if(password == input_password) {
Serial.println("password is correct, here num: ");
// DO YOUR WORK HERE
int numbah = spaces[1].getNumber();
Serial.println(String(numbah));
} else {
Serial.println("password is incorrect, try again");
}
input_password = ""; // clear input password
} else {
input_password += key; // append new character to input password string
}
}
for (auto& space : spaces) { //needs improvement, dont check all the time
space.check();
}
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1
Parking spaces
QR_CODE GENERATOR