Advertisement
pleasedontcode

Arduino Timer rev_01

Dec 29th, 2023
91
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: Arduino Timer
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-29 07:58:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Led turns on and off at intervals of 5 seconds */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /****** SYSTEM REQUIREMENTS *****/
  31. /****** SYSTEM REQUIREMENT 1 *****/
  32.     /* Led turns on and off at intervals of 5 seconds */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t myled_LED_PIN_D2 = 2;
  37.  
  38. // Variable to store the current LED state
  39. bool ledState = LOW;
  40.  
  41. // Variable to store the previous time LED state was updated
  42. unsigned long previousTime = 0;
  43.  
  44. // Interval between LED state changes (in milliseconds)
  45. const unsigned long interval = 5000;
  46.  
  47. void setup(void)
  48. {
  49.     // put your setup code here, to run once:
  50.     pinMode(myled_LED_PIN_D2, OUTPUT);
  51. }
  52.  
  53. void loop(void)
  54. {
  55.     // put your main code here, to run repeatedly:
  56.     unsigned long currentTime = millis(); // Get the current time
  57.  
  58.     // Check if the interval has elapsed
  59.     if (currentTime - previousTime >= interval)
  60.     {
  61.         // Update the LED state
  62.         if (ledState == LOW)
  63.         {
  64.             ledState = HIGH;
  65.         }
  66.         else
  67.         {
  68.             ledState = LOW;
  69.         }
  70.  
  71.         // Update the LED
  72.         digitalWrite(myled_LED_PIN_D2, ledState);
  73.  
  74.         // Update the previous time
  75.         previousTime = currentTime;
  76.     }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement