CCCPaste

Button Control rev_05

/********* 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 Control
	- Source Code compiled for: Arduino Nano
	- Source Code created on: 2024-01-28 17:23:15

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* On LCD1602_LCD1602I2C_I2C display   on the first */
	/* line: CZERWONY "+resultC"  on the second line: */
	/* ZOLTY "+resultZ"  the initial value of resultC and */
	/* resultZ is 10000. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* Holding down the czerwonyP_PushButton subtracts */
	/* from the resultC.  Holding down the */
	/* zielonyP_PushButton subtracts from the resultZ. */
	/* Holding time subtracts value:  1 second subtracts */
	/* randomly 10 to 40, until the button is released. */
/****** END SYSTEM REQUIREMENTS *****/

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

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

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t zielonyP_PushButton_PIN_D2 = 2;
const uint8_t czerwonyP_PushButton_PIN_D3 = 3;

/***** DEFINITION OF I2C PINS *****/
const uint8_t LCD1602_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t LCD1602_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t LCD1602_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;

/****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
EasyButton zielonyP_PushButton(zielonyP_PushButton_PIN_D2);
EasyButton czerwonyP_PushButton(czerwonyP_PushButton_PIN_D3);
LiquidCrystal_I2C lcd(LCD1602_LCD1602I2C_I2C_SLAVE_ADDRESS, LCD1602_LCD1602I2C_I2C_PIN_SDA_A4, LCD1602_LCD1602I2C_I2C_PIN_SCL_A5);

// Variables to hold the result values
int resultC = 10000;
int resultZ = 10000;

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(zielonyP_PushButton_PIN_D2, INPUT_PULLUP);
    pinMode(czerwonyP_PushButton_PIN_D3, INPUT_PULLUP);

    // Initialize the buttons
    zielonyP_PushButton.begin();
    czerwonyP_PushButton.begin();

    // Initialize the LCD
    lcd.begin(16, 2);
    lcd.setBacklight(HIGH);
    lcd.setCursor(0, 0);
    lcd.print("CZERWONY +");
    lcd.setCursor(0, 1);
    lcd.print("ZOLTY +");

    // Display the initial values
    lcd.setCursor(10, 0);
    lcd.print(resultC);
    lcd.setCursor(8, 1);
    lcd.print(resultZ);
}

void loop(void)
{
    // put your main code here, to run repeatedly:

    // Read the status of the buttons
    zielonyP_PushButton.read();
    czerwonyP_PushButton.read();

    // Check if the green button is pressed
    if (zielonyP_PushButton.isPressed())
    {
        // Subtract a random value from resultZ
        int randomValue = random(10, 41);
        resultZ -= randomValue;

        // Update the LCD display for resultZ
        lcd.setCursor(8, 1);
        lcd.print("     ");
        lcd.setCursor(8, 1);
        lcd.print(resultZ);
    }

    // Check if the red button is pressed
    if (czerwonyP_PushButton.isPressed())
    {
        // Subtract a random value from resultC
        int randomValue = random(10, 41);
        resultC -= randomValue;

        // Update the LCD display for resultC
        lcd.setCursor(10, 0);
        lcd.print("     ");
        lcd.setCursor(10, 0);
        lcd.print(resultC);
    }
}