Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: Relay Toggle
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-07-28 08:53:15
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Accendi e spegni il rele ogni 12 ore */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - 'class Relay' has no member named 'loop'
- ********* User code review feedback **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Relay.h> //https://github.com/rafaelnsantos/Relay
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void); // Function prototype for updating outputs
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t rele_RelayModule_Signal_PIN_D2 = 2;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool rele_RelayModule_Signal_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float rele_RelayModule_Signal_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create a relay on pin 2
- Relay relay(rele_RelayModule_Signal_PIN_D2, true); // Initialize relay in Normally Open mode
- // Timing variables
- unsigned long previousMillis = 0; // Store the last time the relay was toggled
- const unsigned long interval = 12 * 60 * 60 * 1000; // 12 hours in milliseconds
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(9600); // Initialize serial communication for debugging
- relay.begin(); // Initialize the relay
- pinMode(rele_RelayModule_Signal_PIN_D2, OUTPUT); // Set the relay pin as output
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- unsigned long currentMillis = millis(); // Get the current time
- // Check if 12 hours have passed
- if (currentMillis - previousMillis >= interval) {
- previousMillis = currentMillis; // Save the last time the relay was toggled
- rele_RelayModule_Signal_PIN_D2_rawData = !rele_RelayModule_Signal_PIN_D2_rawData; // Toggle the relay state
- updateOutputs(); // Refresh output data
- }
- // Removed relay.loop() as it does not exist in the Relay class
- }
- void updateOutputs()
- {
- // Update the relay state based on the raw data
- digitalWrite(rele_RelayModule_Signal_PIN_D2, rele_RelayModule_Signal_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement