#include <LiquidCrystal_I2C.h>
/* ************************************
************************************
** **
** NAME: Josh Shina **
** PROG NAME: Wokwi Lab Test.ino **
** DATE: 2024-10-22 **
** DESC: Simple menu cycler. **
** **
************************************
************************************
*/
// Defines the LCD Display
#define I2C_ADDR 0x27
#define LCD_COLUMNS 2
#define LCD_LINES 16
// Defines the parameters of the display
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int menuVariable = 1;
void setup() {
// Sets the display up by lighting it up and displaying the LED Fader version
lcd.init ();
lcd.backlight ();
lcd.setCursor (0, 0);
lcd.print (" MENU SYSTEM ");
delay (1000);
// Sets up the LED
pinMode (8, OUTPUT);
// Sets up the button as an interrupt
pinMode (2, INPUT_PULLUP);
attachInterrupt (digitalPinToInterrupt (2), menuOption, FALLING);
} // End void setup ()
void loop() {
// Resets cursor location after every loop
lcd.setCursor (0, 0);
// If menuVariable == 4 turn the LED on
if (menuVariable == 4) {
digitalWrite (8, HIGH);
lcd.print(" Winner Menu ");
// Else turn the LED off
} else {
digitalWrite (8, LOW);
if (menuVariable == 1) {
lcd.print (" Main Menu ");
} // End if ()
if (menuVariable == 2) {
lcd.print (" Start Menu ");
} // End if ()
if (menuVariable == 3) {
lcd.print (" Ply Menu ");
} // End if ()
if (menuVariable == 5) {
lcd.print (" Game Over ");
} // End if ()
} // End else
} // End void loop ()
/* *******************************************
*******************************************
** **
** FUNCTION NAME: menuOption **
** INPUTS: N/A **
** OUTPUTS: N/A **
** DESC: Changes menuVariable by 1, **
** capping it at 5, then reseting to 1. **
** **
*******************************************
******************************************* */
void menuOption () {
menuVariable++;
// If menuVariable < 5 set it to 1
if (menuVariable > 5) {
menuVariable = 1;
} // End if ()
} // End void menuOption ()