CCCPaste

"Interactive Clock" rev_10

/********* 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: "Interactive Clock"
	- Source Code compiled for: Arduino Nano
	- Source Code created on: 2024-02-11 13:23:34

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* - lcd_LCD1602I2C_I2C line one: 1CZAS,   second */
	/* line: 2CZAS  - 1CZAS is the time clock, set the */
	/* start value: 7:00  - 2CZAS is the time clock, set */
	/* the start value: 2:00  - 2_PushButton held down */
	/* starts subtracting 0:01 value from 2CZAS every 1 */
	/* second */
/****** SYSTEM REQUIREMENT 2 *****/
	/* - Subtract the value 0:01 from 1CZAS every 1 */
	/* second.  - 2_PushButton released restores the */
	/* initial value of 2CZAS  - The minimum value of */
	/* 1CZAS and 2CZAS is 0:00  - Activate */
	/* b_ActiveBuzzer_output when the minimum value is */
	/* 0:00 */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include     //https://github.com/evert-arias/EasyButton
#include     //https://github.com/marcoschwartz/LiquidCrystal_I2C

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

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

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t ActiveBuzzer_output_PIN_D4 = 4;

/***** DEFINITION OF I2C PINS *****/
const uint8_t lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool ActiveBuzzer_output_PIN_D4_rawData = 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float ActiveBuzzer_output_PIN_D4_phyData = 0.0;

/***** DEFINITION OF CLOCK VARIABLES *****/
int hours = 7;
int minutes = 0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton button(PushButton_PIN_D5);
LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // Initializing LiquidCrystal_I2C object with I2C address and screen size

void setup(void)
{
    // put your setup code here, to run once:

    button.begin();
    pinMode(ActiveBuzzer_output_PIN_D4, OUTPUT);

    lcd.begin(20, 4); // Initializing the LCD module with the screen size

    lcd.setCursor(0, 0);
    lcd.print("7:00");

    lcd.setCursor(0, 1);
    lcd.print("2:00");
}

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

    button.read();

    if (button.wasReleased()) {
        // Reset the clock to initial values
        hours = 7;
        minutes = 0;
    }

    if (button.pressedFor(1000)) {
        // Subtract 1 minute from the second clock
        minutes--;
        if (minutes < 0) {
            minutes = 59;
            hours--;
            if (hours < 0) {
                hours = 0;
            }
        }
    }

    updateClock();
    updateOutputs(); // Refresh output data
}

void updateClock() {
    lcd.setCursor(0, 0);
    if (hours < 10) {
        lcd.print("0"); // Add leading zero if hours less than 10
    }
    lcd.print(hours);
    lcd.print(":");
    if (minutes < 10) {
        lcd.print("0"); // Add leading zero if minutes less than 10
    }
    lcd.print(minutes);
}

void updateOutputs() {
    if (hours == 0 && minutes == 0) {
        ActiveBuzzer_output_PIN_D4_rawData = 1;
    }
    else {
        ActiveBuzzer_output_PIN_D4_rawData = 0;
    }

    digitalWrite(ActiveBuzzer_output_PIN_D4, ActiveBuzzer_output_PIN_D4_rawData);
}