Advertisement
pleasedontcode

RGB Cycling rev_02

Jul 6th, 2025
658
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 Cycling
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-07-06 21:55:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The user requirement should specify the control of */
  21.     /* RGB LEDs connected to pins D4, D13, and D14 on the */
  22.     /* ESP32 DevKit V1, emphasizing digital output */
  23.     /* control and color mixing capabilities. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <FastLED.h>    //https://github.com/FastLED/FastLED
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs();
  35.  
  36. /***** DEFINITION OF OUTPUT PINS AND LED OBJECTS *****/
  37. const uint8_t led_LEDRGB_Red_PIN_D4     = 4;
  38. const uint8_t led_LEDRGB_Green_PIN_D13  = 13;
  39. const uint8_t led_LEDRGB_Blue_PIN_D14   = 14;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data (0-255 for PWM) *****/
  43. uint8_t led_LEDRGB_Red_rawData      = 0;
  44. uint8_t led_LEDRGB_Green_rawData    = 0;
  45. uint8_t led_LEDRGB_Blue_rawData     = 0;
  46.  
  47. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  48. /***** used to store data after characteristic curve transformation *****/
  49. float led_LEDRGB_Red_phyData        = 0.0;
  50. float led_LEDRGB_Green_phyData  = 0.0;
  51. float led_LEDRGB_Blue_phyData       = 0.0;
  52.  
  53. /***** DEFINITION OF PWM LED OBJECTS *****/
  54. CRGB led_Red;
  55. CRGB led_Green;
  56. CRGB led_Blue;
  57.  
  58. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  59.  
  60. void setup(void)
  61. {
  62.     // put your setup code here, to run once:
  63.  
  64.     pinMode(led_LEDRGB_Red_PIN_D4,   OUTPUT);
  65.     pinMode(led_LEDRGB_Green_PIN_D13,    OUTPUT);
  66.     pinMode(led_LEDRGB_Blue_PIN_D14,     OUTPUT);
  67.  
  68.     // Initialize FastLED objects for PWM control
  69.     led_Red = CRGB::Red;
  70.     led_Green = CRGB::Green;
  71.     led_Blue = CRGB::Blue;
  72. }
  73.  
  74. void updateOutputs()
  75. {
  76.     // Map raw data (0-255) to PWM duty cycle
  77.     uint8_t redPWM = led_LEDRGB_Red_rawData;
  78.     uint8_t greenPWM = led_LEDRGB_Green_rawData;
  79.     uint8_t bluePWM = led_LEDRGB_Blue_rawData;
  80.  
  81.     // Write PWM values to pins
  82.     analogWrite(led_LEDRGB_Red_PIN_D4, redPWM);
  83.     analogWrite(led_LEDRGB_Green_PIN_D13, greenPWM);
  84.     analogWrite(led_LEDRGB_Blue_PIN_D14, bluePWM);
  85. }
  86.  
  87. void loop(void)
  88. {
  89.     // put your main code here, to run repeatedly:
  90.  
  91.     updateOutputs(); // Refresh output data
  92.  
  93.     // Example: Cycle colors smoothly (optional)
  94.     // For demonstration, gradually change rawData values
  95.     static uint8_t hue = 0;
  96.     hue++;
  97.     led_LEDRGB_Red_rawData = sin8(hue) / 2 + 127;   // 0-255
  98.     led_LEDRGB_Green_rawData = sin8(hue + 85) / 2 + 127; // Offset hue for variation
  99.     led_LEDRGB_Blue_rawData = sin8(hue + 170) / 2 + 127;
  100.  
  101.     delay(20);
  102. }
  103.  
  104. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement