Advertisement
pleasedontcode

RGB Fade rev_01

Oct 4th, 2024
66
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 Fade
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-04 09:23:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* fade an rgb led through all possible coloiurs over */
  21.     /* a period of 30 second */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h> // Include Arduino library for basic functions
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(); // Function to update the RGB LED outputs
  31.  
  32. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  33. const uint8_t rgbled_LEDRGB_Red_PIN_D2        = 2; // Red pin
  34. const uint8_t rgbled_LEDRGB_Green_PIN_D3      = 3; // Green pin
  35. const uint8_t rgbled_LEDRGB_Blue_PIN_D4       = 4; // Blue pin
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. /***** used to store raw data *****/
  39. uint8_t rgbled_LEDRGB_Red_PIN_D2_rawData      = 0;
  40. uint8_t rgbled_LEDRGB_Green_PIN_D3_rawData    = 0;
  41. uint8_t rgbled_LEDRGB_Blue_PIN_D4_rawData     = 0;
  42.  
  43. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  44. /***** used to store data after characteristic curve transformation *****/
  45. float rgbled_LEDRGB_Red_PIN_D2_phyData        = 0.0;
  46. float rgbled_LEDRGB_Green_PIN_D3_phyData      = 0.0;
  47. float rgbled_LEDRGB_Blue_PIN_D4_phyData       = 0.0;
  48.  
  49. void setup(void)
  50. {
  51.     // Set the RGB LED pins as outputs
  52.     pinMode(rgbled_LEDRGB_Red_PIN_D2, OUTPUT);
  53.     pinMode(rgbled_LEDRGB_Green_PIN_D3, OUTPUT);
  54.     pinMode(rgbled_LEDRGB_Blue_PIN_D4, OUTPUT);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.     // Fade through all colors over a period of 30 seconds
  60.     for (int i = 0; i < 256; i++) {
  61.         // Set the red value
  62.         rgbled_LEDRGB_Red_PIN_D2_rawData = i;
  63.         // Set the green value
  64.         rgbled_LEDRGB_Green_PIN_D3_rawData = 255 - i;
  65.         // Set the blue value
  66.         rgbled_LEDRGB_Blue_PIN_D4_rawData = (i < 128) ? 0 : (i - 128) * 2;
  67.  
  68.         updateOutputs(); // Refresh output data
  69.         delay(117); // Delay to achieve a total of 30 seconds for the full cycle
  70.     }
  71. }
  72.  
  73. void updateOutputs()
  74. {
  75.     // Update the RGB LED with the current raw data values
  76.     analogWrite(rgbled_LEDRGB_Red_PIN_D2, rgbled_LEDRGB_Red_PIN_D2_rawData);
  77.     analogWrite(rgbled_LEDRGB_Green_PIN_D3, rgbled_LEDRGB_Green_PIN_D3_rawData);
  78.     analogWrite(rgbled_LEDRGB_Blue_PIN_D4, rgbled_LEDRGB_Blue_PIN_D4_rawData);
  79. }
  80.  
  81. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement