CCCPaste

**LED Control** rev_02

/********* 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: **LED Control**
	- Source Code NOT compiled for: ESP8266 NodeMCU V1.0
	- Source Code created on: 2024-11-27 14:46:31

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* LCD Menu with Options */
/****** SYSTEM REQUIREMENT 2 *****/
	/* simple menu for your LCD          program a menu */
	/* to control led on and off using a key */
/****** END SYSTEM REQUIREMENTS *****/

/* START CODE */

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void displayMenu(void);
void controlLED(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t B_PushButton_PIN_D5 = 5;

/***** DEFINITION OF I2C PINS *****/
const uint8_t A_LCD1602I2C_I2C_PIN_SDA_D2 = 2;
const uint8_t A_LCD1602I2C_I2C_PIN_SCL_D1 = 1;
const uint8_t A_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;

/***** LCD Configuration *****/
LiquidCrystal_I2C lcd(A_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize LCD with I2C address, columns, and rows

bool ledState = false; // Variable to hold the LED state

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(B_PushButton_PIN_D5, INPUT_PULLUP);
    lcd.begin(); // Initialize the LCD
    lcd.backlight(); // Turn on the backlight
    displayMenu(); // Display the menu on the LCD
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    if (digitalRead(B_PushButton_PIN_D5) == LOW) { // Check if the button is pressed
        controlLED(); // Control the LED based on the button press
        delay(500); // Debounce delay
    }
}

void displayMenu(void)
{
    lcd.clear(); // Clear the LCD
    lcd.setCursor(0, 0); // Set cursor to the first line
    lcd.print("LED Control Menu"); // Display menu title
    lcd.setCursor(0, 1); // Set cursor to the second line
    lcd.print("Press button"); // Prompt user to press the button
}

void controlLED(void)
{
    ledState = !ledState; // Toggle LED state
    if (ledState) {
        // Code to turn on the LED
        digitalWrite(LED_BUILTIN, HIGH); // Assuming LED_BUILTIN is used
        lcd.setCursor(0, 1); // Set cursor to the second line
        lcd.print("LED: ON      "); // Update display
    } else {
        // Code to turn off the LED
        digitalWrite(LED_BUILTIN, LOW); // Assuming LED_BUILTIN is used
        lcd.setCursor(0, 1); // Set cursor to the second line
        lcd.print("LED: OFF     "); // Update display
    }
}

/* END CODE */