#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 columns and 2 rows
const int buttonPin = 4; // Change to your button pin
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Press button!");
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with pull-up resistor
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // Button pressed
int randomValue = random(2); // 0 or 1
lcd.setCursor(0, 1);
if (randomValue == 0) {
lcd.print("Heads");
} else {
lcd.print("Tails");
}
delay(1000); // Delay for readability
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Press button!");
}
}