Advertisement
pleasedontcode

RGB LED Control rev_01

Apr 27th, 2024
93
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: RGB LED Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-27 16:00:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* In a cycle, automatically turn on led for only 30 */
  21.     /* sec then stop for 10 sec and repreat */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void);
  30.  
  31. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  32. const uint8_t led_LEDRGB_Red_PIN_D2     = 2;
  33. const uint8_t led_LEDRGB_Green_PIN_D3   = 3;
  34. const uint8_t led_LEDRGB_Blue_PIN_D4    = 4;
  35.  
  36. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  37. /***** used to store raw data *****/
  38. bool    led_LEDRGB_Red_PIN_D2_rawData   = 0;
  39. bool    led_LEDRGB_Green_PIN_D3_rawData = 0;
  40. bool    led_LEDRGB_Blue_PIN_D4_rawData  = 0;
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. /***** used to store data after characteristic curve transformation *****/
  44. float   led_LEDRGB_Red_PIN_D2_phyData   = 0.0;
  45. float   led_LEDRGB_Green_PIN_D3_phyData = 0.0;
  46. float   led_LEDRGB_Blue_PIN_D4_phyData  = 0.0;
  47.  
  48. unsigned long previousMillis = 0;
  49. const long onTime = 30000; // 30 seconds
  50. const long offTime = 10000; // 10 seconds
  51. bool ledState = LOW;
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.     pinMode(led_LEDRGB_Red_PIN_D2,   OUTPUT);
  57.     pinMode(led_LEDRGB_Green_PIN_D3, OUTPUT);
  58.     pinMode(led_LEDRGB_Blue_PIN_D4,  OUTPUT);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // put your main code here, to run repeatedly:
  64.     unsigned long currentMillis = millis();
  65.  
  66.     if (ledState == LOW && currentMillis - previousMillis >= offTime)
  67.     {
  68.         previousMillis = currentMillis;
  69.         ledState = HIGH;
  70.     }
  71.     else if (ledState == HIGH && currentMillis - previousMillis >= onTime)
  72.     {
  73.         previousMillis = currentMillis;
  74.         ledState = LOW;
  75.     }
  76.  
  77.     digitalWrite(led_LEDRGB_Red_PIN_D2, ledState);
  78.     digitalWrite(led_LEDRGB_Green_PIN_D3, ledState);
  79.     digitalWrite(led_LEDRGB_Blue_PIN_D4, ledState);
  80. }
  81.  
  82. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement