// **********************************************
// * *
// * NAME : Ahmad Hamzeh *
// * Program Name : Arduino LAB TEST.ino *
// * Date : 2023-04-14 *
// * Desc : LED with rotating pattern *
// * *
// * *
// * *
// **********************************************
#include <LiquidCrystal_I2C.h> // includes lcd in the program
#define I2C_ADDR 0x27 // defining graphics for lcd
#define LCD_COLUMNS 16 // defining width
#define LCD_LINES 2 // defining length
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const int LED = 8;
const int button = 2;
int variable = 1;
void setup() {
pinMode(LED, OUTPUT);
pinMode(button, INPUT_PULLUP);
// put your setup code here, to run once:
lcd.init(); // // initializing lcd
lcd.backlight(); // turn on backlight
lcd.setCursor(0, 0);// set cursor
lcd.print("* MENU SYSTEM *"); // print wanted message-
delay(1000);
lcd.print("Main Menu");
attachInterrupt(digitalPinToInterrupt(button),menuOption, FALLING);
} //end setup
void loop() {
// put your main code here, to run repeatedly:
if (variable == 1) {
lcd.setCursor(3,0);
lcd.print("Main Menu");
digitalWrite(LED, LOW);
} // end if
else if (variable == 2){
lcd.setCursor(3,0);
lcd.print("Start Menu");
digitalWrite(LED, LOW);
} // end else if
else if (variable == 3){
lcd.setCursor(3,0);
lcd.print("Ply Menu");
digitalWrite(LED, LOW);
} // end else if
else if (variable == 4){
lcd.setCursor(3,0);
lcd.print("Winner Menu");
digitalWrite(LED, HIGH);
} // end else if
else if (variable == 5){
lcd.setCursor(3,0);
lcd.print("Game Over");
digitalWrite(LED, LOW);
} // end else if
} //end loop
void menuOption() {
static unsigned long last_interrupt_time = 0; //debounce template:
unsigned long interrupt_time = millis();
variable = variable + 1;
if (variable == 6) {
variable = 1;
} // end else if
last_interrupt_time = interrupt_time;
}