// ********************************************************************
// * *
// * NAME : Shaan Sandhu *
// * Program Name: Arduino lab test B *
// * Date : 2023-04-14 *
// * Desc : click a button to display a message *
// * *
// ********************************************************************
int button = 3;
int led = 10;
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
pinMode(led, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("*MENU SYSTEM*");
delay(1000);
pinMode(button, INPUT_PULLUP);
attachInterrupt( digitalPinToInterrupt(button), menuOption, FALLING);
} // end setup
void loop() {
if (digitalRead(button) == 0) {
lcd.print("*FIRST MENU*");
} // end if
if (digitalRead(button) == 0) {
lcd.print("*START UP MENU*");
} // end if
if (digitalRead(button) == 0) {
lcd.print("*Play Menu*");
} // enf if
if (digitalRead(button) == 0) {
lcd.print("*Win Menu*");
} // end if
digitalWrite(led, HIGH);
if (digitalRead(button) == 0) {
lcd.print("*Game Fin*");
} // end if
} // end loop
void menuOption() {
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 200) {
last_interrupt_time = interrupt_time;
} // end if
if (interrupt_time - last_interrupt_time > 300) {
last_interrupt_time = interrupt_time;
} // end if
if (interrupt_time - last_interrupt_time > 400) {
last_interrupt_time = interrupt_time;
} // end if
if (interrupt_time - last_interrupt_time > 500) {
last_interrupt_time = interrupt_time;
} // end if
if (interrupt_time - last_interrupt_time > 600) {
last_interrupt_time = interrupt_time;
}// end if()
} // end function