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 Fade
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-04 09:23:35
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* fade an rgb led through all possible coloiurs over */
- /* a period of 30 second */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h> // Include Arduino library for basic functions
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(); // Function to update the RGB LED outputs
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t rgbled_LEDRGB_Red_PIN_D2 = 2; // Red pin
- const uint8_t rgbled_LEDRGB_Green_PIN_D3 = 3; // Green pin
- const uint8_t rgbled_LEDRGB_Blue_PIN_D4 = 4; // Blue pin
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- uint8_t rgbled_LEDRGB_Red_PIN_D2_rawData = 0;
- uint8_t rgbled_LEDRGB_Green_PIN_D3_rawData = 0;
- uint8_t rgbled_LEDRGB_Blue_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float rgbled_LEDRGB_Red_PIN_D2_phyData = 0.0;
- float rgbled_LEDRGB_Green_PIN_D3_phyData = 0.0;
- float rgbled_LEDRGB_Blue_PIN_D4_phyData = 0.0;
- void setup(void)
- {
- // Set the RGB LED pins as outputs
- pinMode(rgbled_LEDRGB_Red_PIN_D2, OUTPUT);
- pinMode(rgbled_LEDRGB_Green_PIN_D3, OUTPUT);
- pinMode(rgbled_LEDRGB_Blue_PIN_D4, OUTPUT);
- }
- void loop(void)
- {
- // Fade through all colors over a period of 30 seconds
- for (int i = 0; i < 256; i++) {
- // Set the red value
- rgbled_LEDRGB_Red_PIN_D2_rawData = i;
- // Set the green value
- rgbled_LEDRGB_Green_PIN_D3_rawData = 255 - i;
- // Set the blue value
- rgbled_LEDRGB_Blue_PIN_D4_rawData = (i < 128) ? 0 : (i - 128) * 2;
- updateOutputs(); // Refresh output data
- delay(117); // Delay to achieve a total of 30 seconds for the full cycle
- }
- }
- void updateOutputs()
- {
- // Update the RGB LED with the current raw data values
- analogWrite(rgbled_LEDRGB_Red_PIN_D2, rgbled_LEDRGB_Red_PIN_D2_rawData);
- analogWrite(rgbled_LEDRGB_Green_PIN_D3, rgbled_LEDRGB_Green_PIN_D3_rawData);
- analogWrite(rgbled_LEDRGB_Blue_PIN_D4, rgbled_LEDRGB_Blue_PIN_D4_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement