pleasedontcode

Timed Blink rev_15

Oct 16th, 2025
263
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: Timed Blink
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-10-16 17:12:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* blink led every 2 seconds */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. // Global variables for LED blinking
  33. const int LED_PIN = 13;
  34. const unsigned long BLINK_INTERVAL_MS = 2000;
  35. const unsigned long BLINK_DURATION_MS = 60000;
  36. unsigned long previousMillis = 0;
  37. unsigned long startMillis = 0;
  38. bool ledState = LOW; // 0 = OFF, 1 = ON
  39.  
  40. void setup(void)
  41. {
  42.     // put your setup code here, to run once:
  43.     pinMode(LED_PIN, OUTPUT);
  44.     startMillis = millis();
  45.     previousMillis = 0;
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     unsigned long currentMillis = millis();
  51.     unsigned long elapsed = currentMillis - startMillis;
  52.  
  53.     if (elapsed < BLINK_DURATION_MS) {
  54.         if (currentMillis - previousMillis >= BLINK_INTERVAL_MS) {
  55.             previousMillis = currentMillis;
  56.             ledState = !ledState;
  57.             digitalWrite(LED_PIN, ledState ? HIGH : LOW);
  58.         }
  59.     } else {
  60.         // Stop blinking after the duration
  61.         if (ledState != LOW) {
  62.             ledState = LOW;
  63.             digitalWrite(LED_PIN, LOW);
  64.         }
  65.     }
  66.     // Display update code would go here (if present)
  67. }
  68.  
  69. /* END CODE */
  70.  
Advertisement
Add Comment
Please, Sign In to add comment