pleasedontcode

Toggle Loop rev_04

Aug 3rd, 2025
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Toggle Loop
  13.     - Source Code compiled for: Arduino Opta WiFi
  14.     - Source Code created on: 2025-08-03 09:41:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Toggle relay 1 and its associated LED every 3 */
  21.     /* seconds using the connected relay and LED */
  22.     /* components on the Arduino Opta WiFi board. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25.  
  26. /********* User code review feedback **********
  27. #### Feedback 1 ####
  28. - put on serial monitor led state
  29. ********* User code review feedback **********/
  30.  
  31. /* START CODE */
  32. /****** DEFINITION OF LIBRARIES *****/
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. // Define pin numbers for relay and LED
  39. const int relayPin = 2; // Replace with actual relay pin if different
  40. const int ledPin = 3;   // Replace with actual LED pin if different
  41.  
  42. // Variable to keep track of relay and LED state
  43. bool relayState = false;
  44.  
  45. void setup(void)
  46. {
  47.     // Initialize relay and LED pins as outputs
  48.     pinMode(relayPin, OUTPUT);
  49.     pinMode(ledPin, OUTPUT);
  50.  
  51.     // Ensure relay and LED are off at start
  52.     digitalWrite(relayPin, LOW);
  53.     digitalWrite(ledPin, LOW);
  54.  
  55.     // Initialize serial communication at 9600 baud rate
  56.     Serial.begin(9600);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.     // Toggle relay and LED states
  62.     relayState = !relayState;
  63.     digitalWrite(relayPin, relayState ? HIGH : LOW);
  64.     digitalWrite(ledPin, relayState ? HIGH : LOW);
  65.  
  66.     // Output the LED state to serial monitor
  67.     Serial.print("LED State: ");
  68.     Serial.println(relayState ? "ON" : "OFF");
  69.  
  70.     // Wait for 3 seconds
  71.     delay(3000);
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment