Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: RGB Cycling
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2025-07-06 21:55:46
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The user requirement should specify the control of */
- /* RGB LEDs connected to pins D4, D13, and D14 on the */
- /* ESP32 DevKit V1, emphasizing digital output */
- /* control and color mixing capabilities. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- /***** DEFINITION OF OUTPUT PINS AND LED OBJECTS *****/
- const uint8_t led_LEDRGB_Red_PIN_D4 = 4;
- const uint8_t led_LEDRGB_Green_PIN_D13 = 13;
- const uint8_t led_LEDRGB_Blue_PIN_D14 = 14;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data (0-255 for PWM) *****/
- uint8_t led_LEDRGB_Red_rawData = 0;
- uint8_t led_LEDRGB_Green_rawData = 0;
- uint8_t led_LEDRGB_Blue_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float led_LEDRGB_Red_phyData = 0.0;
- float led_LEDRGB_Green_phyData = 0.0;
- float led_LEDRGB_Blue_phyData = 0.0;
- /***** DEFINITION OF PWM LED OBJECTS *****/
- CRGB led_Red;
- CRGB led_Green;
- CRGB led_Blue;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(led_LEDRGB_Red_PIN_D4, OUTPUT);
- pinMode(led_LEDRGB_Green_PIN_D13, OUTPUT);
- pinMode(led_LEDRGB_Blue_PIN_D14, OUTPUT);
- // Initialize FastLED objects for PWM control
- led_Red = CRGB::Red;
- led_Green = CRGB::Green;
- led_Blue = CRGB::Blue;
- }
- void updateOutputs()
- {
- // Map raw data (0-255) to PWM duty cycle
- uint8_t redPWM = led_LEDRGB_Red_rawData;
- uint8_t greenPWM = led_LEDRGB_Green_rawData;
- uint8_t bluePWM = led_LEDRGB_Blue_rawData;
- // Write PWM values to pins
- analogWrite(led_LEDRGB_Red_PIN_D4, redPWM);
- analogWrite(led_LEDRGB_Green_PIN_D13, greenPWM);
- analogWrite(led_LEDRGB_Blue_PIN_D14, bluePWM);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // Example: Cycle colors smoothly (optional)
- // For demonstration, gradually change rawData values
- static uint8_t hue = 0;
- hue++;
- led_LEDRGB_Red_rawData = sin8(hue) / 2 + 127; // 0-255
- led_LEDRGB_Green_rawData = sin8(hue + 85) / 2 + 127; // Offset hue for variation
- led_LEDRGB_Blue_rawData = sin8(hue + 170) / 2 + 127;
- delay(20);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement