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: Toggle Loop
- - Source Code compiled for: Arduino Opta WiFi
- - Source Code created on: 2025-08-03 09:41:18
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Toggle relay 1 and its associated LED every 3 */
- /* seconds using the connected relay and LED */
- /* components on the Arduino Opta WiFi board. */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - put on serial monitor led state
- ********* User code review feedback **********/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Define pin numbers for relay and LED
- const int relayPin = 2; // Replace with actual relay pin if different
- const int ledPin = 3; // Replace with actual LED pin if different
- // Variable to keep track of relay and LED state
- bool relayState = false;
- void setup(void)
- {
- // Initialize relay and LED pins as outputs
- pinMode(relayPin, OUTPUT);
- pinMode(ledPin, OUTPUT);
- // Ensure relay and LED are off at start
- digitalWrite(relayPin, LOW);
- digitalWrite(ledPin, LOW);
- // Initialize serial communication at 9600 baud rate
- Serial.begin(9600);
- }
- void loop(void)
- {
- // Toggle relay and LED states
- relayState = !relayState;
- digitalWrite(relayPin, relayState ? HIGH : LOW);
- digitalWrite(ledPin, relayState ? HIGH : LOW);
- // Output the LED state to serial monitor
- Serial.print("LED State: ");
- Serial.println(relayState ? "ON" : "OFF");
- // Wait for 3 seconds
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment