#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // I2C address for the LCD
#define LCD_COLUMNS 16 // Number of columns on the LCD
#define LCD_LINES 2 // Number of lines on the LCD
#define btnPin 2 // Button pin (changed to pin 2)
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight(); // Turn on the backlight
// Set the button pin as input with internal pull-up
pinMode(btnPin, INPUT_PULLUP);
}
void loop() {
bool btn = digitalRead(btnPin); // Read the button state
if (btn == LOW) { // If the button is pressed (LOW because it's configured as INPUT_PULLUP)
lcd.setCursor(0, 0); // Set cursor to the first line, first column
lcd.print("Calling"); // Print "Calling" on the first line
lcd.setCursor(0, 1); // Set cursor to the second line, first column
lcd.print("911"); // Print "911" on the second line
delay(500); // Wait for 500 ms
lcd.clear(); // Clear the screen
lcd.setCursor(0, 0); // Set cursor to the first line, first column
lcd.print("Calling"); // Print "Calling" on the first line
lcd.setCursor(0, 1); // Set cursor to the second line, first column
lcd.print("911");
delay(500);
lcd.clear();
delay(15);
lcd.setCursor(0, 0); // Set cursor back to the first line
for (int i = 0; i < 10; i++) { // Loop to print 10 dots
lcd.print("."); // Print one dot
delay(100); // Delay of 100 ms between dots
}
lcd.clear(); // Clear the screen again
lcd.setCursor(0, 0); // Set cursor to the first line
lcd.print("Help is on"); // Display the next step message
lcd.setCursor(0, 1); // Move to the second line
lcd.print("the way!"); // Display additional message
delay(2000); // Wait for 2 seconds
lcd.clear(); // Optionally, clear the screen after the message is shown
} else {
// Optional: You can leave this part empty, or display a message when not pressed
lcd.clear(); // Clear screen if button is not pressed
}
delay(100); // Small delay to debounce the button press
}