#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BUTTON_PIN 2
#define PRESS_THRESHOLD 5
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 or 0x3F
int buttonState = 0;
int lastButtonState = 0;
int pressCount = 0;
bool madMode = false;
void setup() {
// Initialize the LCD
lcd.begin(16, 2, LCD_5x8DOTS); // Specify the dimensions of the LCD and character size
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Press the button!");
// Initialize the button pin as input
pinMode(BUTTON_PIN, INPUT_PULLUP);
Serial.begin(9600); // For debugging purposes
}
void loop() {
// Read the current state of the button
buttonState = digitalRead(BUTTON_PIN);
// Check if the button is pressed
if (buttonState == LOW && lastButtonState == HIGH) {
pressCount++;
delay(50); // Debounce delay
updateLCD();
}
// Update the last button state
lastButtonState = buttonState;
// If mad mode is triggered, spam messages
if (madMode) {
spamMessages();
}
}
void updateLCD() {
lcd.clear();
if (pressCount >= PRESS_THRESHOLD) {
madMode = true;
} else {
lcd.print("Press count: ");
lcd.setCursor(0, 1);
lcd.print(pressCount);
}
// For debugging purposes
Serial.print("Button pressed ");
Serial.print(pressCount);
Serial.println(" times.");
}
void spamMessages() {
String messages[] = {
"Don't touch that!",
"I'm warning you.",
"Seriously, stop.",
"Why don't you listen?",
"That's enough!"
};
for (int i = 0; i < 5; i++) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(messages[i]);
delay(1000); // Display each message for 1 second
}
}