/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: **Button Status**
- Source Code NOT compiled for: Arduino Mega
- Source Code created on: 2024-11-24 21:10:56
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* this part, your Arduino board’s LCD */
/* display will appear have the */
/* following display when no button is */
/* being pressed: and the following */
/* display when any button is being */
/* pressed: and this behavior */
/* continues as long as the Arduino */
/* runs */
/****** END SYSTEM REQUIREMENTS *****/
/* START CODE */
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/marcoschwartz/LiquidCrystal_I2C
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF I2C PINS *****/
const uint8_t LCD_LCD1602I2C_I2C_PIN_SDA_D20 = 20;
const uint8_t LCD_LCD1602I2C_I2C_PIN_SCL_D21 = 21;
const uint8_t LCD_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an instance of the LiquidCrystal_I2C class
LiquidCrystal_I2C lcd(LCD_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // 16 columns and 2 rows
/****** BUTTON PINS *****/
const int buttonPin = 2; // Pin where the button is connected
void setup(void)
{
// Initialize the LCD
lcd.begin(16, 2); // Initialize the LCD with the number of columns and rows
lcd.backlight(); // Turn on the backlight
// Set the button pin as input
pinMode(buttonPin, INPUT);
// Display initial message
lcd.print("No Button Pressed");
}
void loop(void)
{
// Check if the button is pressed
if (digitalRead(buttonPin) == HIGH) {
lcd.clear(); // Clear the display
lcd.print("Button Pressed"); // Display message when button is pressed
} else {
lcd.clear(); // Clear the display
lcd.print("No Button Pressed"); // Display message when no button is pressed
}
delay(100); // Small delay to avoid flickering
}
/* END CODE */