#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
// Define the pin for the LED
#define LED_PIN 5
// Define the pin for the button
#define BUTTON_PIN 6
#define BUZZER_PIN 8
void setup() {
lcd.init();
lcd.backlight();
// Set the LED pin as an output
pinMode(LED_PIN, OUTPUT);
// Set the button pin as an input
pinMode(BUTTON_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
// This part will show and write all the output processed by Arduino
lcd.setCursor(4, 0);
lcd.print("Welcome");
lcd.setCursor(2, 1);
lcd.print("Quiz Alarm");
delay(4000);
lcd.clear();
}
void tetot() {
tone(BUZZER_PIN, 300);
delay(300);
tone(BUZZER_PIN, 200);
delay(500);
noTone(BUZZER_PIN);
}
void loop() {
// Read the state of the button
int buttonState = digitalRead(BUTTON_PIN);
// Set cursor to the first line
lcd.setCursor(0, 0);
lcd.print("Status: ");
if (buttonState == LOW) {
digitalWrite(LED_PIN, LOW);
lcd.print("OFF ");
noTone(BUZZER_PIN);
} else { // Button is not pressed
tetot();
digitalWrite(LED_PIN, HIGH);
lcd.print("ON ");
delay(300);
}
}