Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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:58:41 ********* 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' #### Feedback 2 #### - avvia con il rele normalmente chiuso ********* User code review feedback **********/ /****** DEFINITION OF LIBRARIES *****/ #include
//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 = 1; // Start with relay ON (Normally Closed) /***** 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, false); // Initialize relay in Normally Closed 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 updateOutputs(); // Ensure the initial state is set correctly } 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 } } 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 */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)