#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Initialize the I2C LCD with address 0x27 and 20 columns, 4 rows
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Define the keypad configuration
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Define the correct codes and associated messages
const char* codes[] = {
"62139C3", "75B6813", "9B10152", "C135982", "B202183902764C",
"70264", "81087", "1234", "80085", "A201731928761D",
"11073", "5486", "D1C", "B00B5", "5318008",
"DAD", "8055", "00761"
};
const char* messages[][4] = {
{" CODE FRAGMENT 1:", " From 1 to 5", "The first two digits", " add up to seven."},
{" CODE FRAGMENT 2:", " IMAGINE A NOKIA", " 9999, 33, 777, 666", " 8, 9, 666"},
{" CODE FRAGMENT 3:", " Between 70 and 80", " I add up to 15", " What number am I?"},
{" Hint: ", " Double the odds.", " Zero is nothing.", " Ascension is key."},
{" Stage 1 Complete", "", " Go to Checkpoint", " Five"},
{" Stage 2 Complete", "", " Go to Checkpoint", " One"},
{" Stage 3 Complete", "", "The cache is within", "20m of the pond."},
{" HAHA! Nice Try", "", " Now get to work!", ""},
{" BOOBS... Really?", "", " I like boobs too", " Now get to work!"},
{" Stage 1 Complete", "", " Go to Checkpoint", " Six"},
{" Stage 2 Complete", "", " Go to Checkpoint", " Seven"},
{" Stage 3 Complete", "", "The cache is by the", "large machine gun."},
{"Well...", "You look like you", "suck a lot of dick.", "with your arsehole."},
{"Soft curves,", "a gentle sway", "beauty in their", "own jiggly way"},
{" (. V .)", " ) . (", " ( Y )", ""},
{"I'm not your dad...", "", "But, if you pay me", "I could be... ;-)"},
{"Come on now...", "You play airsoft", "to escape your boss.", "Dont bring work here"},
{"Igloo (noun):", "A house made of ice", "that funny little", "Chinese people live"}
};
String inputCode = "";
// Define the reset button pin
const int resetButtonPin = 12;
// Flag to track message display mode
bool messageDisplayed = false;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Enter Code:");
pinMode(9, OUTPUT); // Buzzer
pinMode(resetButtonPin, INPUT_PULLUP); // Set reset button pin as input with pull-up resistor
}
void loop() {
// Check if the reset button is pressed
if (messageDisplayed) {
// Wait for any button to be pressed to reset the display
char key = keypad.getKey();
if (key) {
resetDisplay();
}
} else {
char key = keypad.getKey();
if (key) {
if (key == '#') {
// Process input and display appropriate message
bool found = false;
for (int i = 0; i < sizeof(codes) / sizeof(codes[0]); i++) {
if (inputCode == codes[i]) {
displayMessage(messages[i][0], messages[i][1], messages[i][2], messages[i][3]);
found = true;
break;
}
}
if (!found) {
displayMessage("Access Denied", "", "", "");
}
inputCode = "";
} else if (key == '*') {
if (inputCode.length() > 0) {
// Delete the last character
inputCode = inputCode.substring(0, inputCode.length() - 1);
lcd.setCursor(inputCode.length(), 1); // Set the cursor to the new end of the input
lcd.print(" "); // Clear the last character on the LCD
lcd.setCursor(inputCode.length(), 1); // Move the cursor back to the new end
}
} else {
// Add the character to the input code and display it
inputCode += key;
lcd.setCursor(inputCode.length() - 1, 1);
lcd.print(key);
}
}
}
}
// Function to reset the display
void resetDisplay() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Code:");
messageDisplayed = false;
}
// Function to display message with typing effect
void displayMessage(const char* line1, const char* line2, const char* line3, const char* line4) {
lcd.clear();
typeLine(line1, 0); // Line 1
typeLine(line2, 1); // Line 2
typeLine(line3, 2); // Line 3
typeLine(line4, 3); // Line 4
messageDisplayed = true;
// Adjust tone based on message
tone(10, line1[0] == 'A' ? 1000 : 100, 200);
delay(1000);
}
// Helper function to simulate typing effect
void typeLine(const char* text, int line) {
lcd.setCursor(0, line); // Set the cursor to the beginning of the line
for (int i = 0; i < strlen(text); i++) {
lcd.print(text[i]); // Print each character
delay(100); // Add delay between each character (100ms for typing effect)
}
}