CCCPaste

"Real-Time Relay" rev_01

/********* 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: "Real-Time Relay"
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-05-29 20:43:54

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* یک سیستم کنترل رله را با یک دکمه روی پایه D2 طراحی */
	/* کنید. رله را در تابع راه اندازی اولیه کنید و به */
	/* طور مداوم وضعیت آن را در تابع حلقه بر اساس ورودی */
	/* داده خام دکمه به روز کنید. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include  //https://github.com/rafaelnsantos/Relay

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

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Button_PIN_D2 = 2; // Button connected to pin D2
const uint8_t Relay_PIN = 3; // Relay connected to pin D3

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

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

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Relay light(Relay_PIN, true); // Initialize relay on pin 3, Normally Open

void setup(void)
{
    // put your setup code here, to run once:
    pinMode(Button_PIN_D2, INPUT); // Initialize the button pin as input
    light.begin(); // Initialize the relay pin
}

void loop(void)
{
    // put your main code here, to run repeatedly:
    updateOutputs(); // Refresh output data
}

void updateOutputs()
{
    // Read the button state
    Button_PIN_D2_rawData = digitalRead(Button_PIN_D2);

    // Update relay state based on button input
    if (Button_PIN_D2_rawData)
    {
        light.turnOn(); // Turn relay on if button is pressed
    }
    else
    {
        light.turnOff(); // Turn relay off if button is not pressed
    }

    // Get relay state and update raw data
    Button_PIN_D2_rawData = light.getState();
    digitalWrite(Relay_PIN, Button_PIN_D2_rawData);
}

/* END CODE */