#include <Wire.h> // include Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // include LiquidCrystal_I2C library for LCD display
// define the I2C address of the LCD
#define I2C_ADDR 0x27
// define the dimensions of the LCD (16 columns and 2 rows)
#define LCD_COLS 16
#define LCD_ROWS 2
// create an instance of the LiquidCrystal_I2C library with the I2C address and dimensions
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLS, LCD_ROWS);
// define the pin for the buttons
#define BUTTON_1_PIN 2
#define BUTTON_2_PIN 3
#define BUTTON_3_PIN 4
#define BUTTON_4_PIN 5
#define BUTTON_5_PIN 6
#define BUTTON_6_PIN 7
// define the correct sequence of button presses
const int BUTTON_SEQUENCE[] = {BUTTON_5_PIN, BUTTON_2_PIN, BUTTON_6_PIN, BUTTON_1_PIN, BUTTON_3_PIN, BUTTON_4_PIN, BUTTON_6_PIN, BUTTON_1_PIN, BUTTON_3_PIN, BUTTON_4_PIN};
// define the length of the button sequence
#define BUTTON_SEQUENCE_LENGTH 10
// define the message to display when the correct sequence is entered
const char* SUCCESS_MESSAGE_LINE1 = "Sequence Correct!";
const char* SUCCESS_MESSAGE_LINE2 = "Cipher Key Is:";
const char* SUCCESS_MESSAGE_LINE3= "ABCDEF-YZ";
const char* SUCCESS_MESSAGE_LINE4= "Message Complete";
const char* SUCCESS_MESSAGE_LINE5= "LMNOPQ-JK";
// define a variable to keep track of the current button press in the sequence
int currentButtonPress = 0;
void setup() {
// initialize the LCD display
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Correct");
lcd.setCursor(0,1);
lcd.print("Color Sequence:");
// initialize the button pins
pinMode(BUTTON_1_PIN, INPUT_PULLUP);
pinMode(BUTTON_2_PIN, INPUT_PULLUP);
pinMode(BUTTON_3_PIN, INPUT_PULLUP);
pinMode(BUTTON_4_PIN, INPUT_PULLUP);
pinMode(BUTTON_5_PIN, INPUT_PULLUP);
pinMode(BUTTON_6_PIN, INPUT_PULLUP);
}
void loop() {
// check if the current button in the sequence is pressed
if (digitalRead(BUTTON_SEQUENCE[currentButtonPress]) == LOW) {
// move to the next button in the sequence
currentButtonPress++;
// check if the entire sequence has been entered correctly
if (currentButtonPress == BUTTON_SEQUENCE_LENGTH) {
// display the success message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE1);
delay(1000);
lcd.setCursor(0, 1);
lcd.print(SUCCESS_MESSAGE_LINE2);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE3);
lcd.setCursor(0, 1);
lcd.print(SUCCESS_MESSAGE_LINE5);
delay(4000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE1);
delay(1000);
lcd.setCursor(0, 1);
lcd.print(SUCCESS_MESSAGE_LINE2);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE3);
lcd.setCursor(0, 1);
lcd.print(SUCCESS_MESSAGE_LINE5);
delay(4000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE1);
delay(1000);
lcd.setCursor(0, 1);
lcd.print(SUCCESS_MESSAGE_LINE2);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE3);
lcd.setCursor(0, 1);
lcd.print(SUCCESS_MESSAGE_LINE5);
delay(4000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(SUCCESS_MESSAGE_LINE4);
// reset the button sequence tracker
currentButtonPress = 0;
}
}
}