Advertisement
pleasedontcode

Colorful Fading rev_06

May 1st, 2024
217
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: Colorful Fading
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-01 10:39:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* chipset WS2812B RGB  Number of LED 20  Output D5 */
  21.     /* fade in and out from 0 to 255 while keeping color */
  22.     /* set fade out value at 255  use all colors randomly */
  23.     /* for each led and */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <FastLED.h> // https://github.com/FastLED/FastLED
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void); // Added function prototype for updateOutputs
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t WS2812B_LEDRGB_PIN_D5 = 5; // Define output pin for WS2812B LEDs
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. /***** used to store raw data *****/
  39. bool WS2812B_LEDRGB_PIN_D5_rawData = 0;
  40.  
  41. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  42. /***** used to store data after characteristic curve transformation *****/
  43. float WS2812B_LEDRGB_PIN_D5_phyData = 0.0;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. CRGB leds[20]; // Define CRGB array for 20 LEDs
  47.  
  48. void setup(void)
  49. {
  50.     // put your setup code here, to run once:
  51.  
  52.     pinMode(WS2812B_LEDRGB_PIN_D5, OUTPUT);
  53.  
  54.     // Initialize FastLED library object
  55.     FastLED.addLeds<WS2812B, WS2812B_LEDRGB_PIN_D5>(leds, 20);
  56. }
  57.  
  58. void loop(void)
  59. {
  60.     // put your main code here, to run repeatedly:
  61.  
  62.     updateOutputs(); // Refresh output data
  63. }
  64.  
  65. void updateOutputs()
  66. {
  67.     // Generate random color values for each LED
  68.     for (int i = 0; i < 20; i++)
  69.     {
  70.         leds[i] = CHSV(random8(), 255, 255); // Random hue, full saturation and value
  71.     }
  72.  
  73.     // Fade in and out effect
  74.     for (int brightness = 0; brightness <= 255; brightness++)
  75.     {
  76.         for (int i = 0; i < 20; i++)
  77.         {
  78.             leds[i].fadeToBlackBy(255 - brightness); // Fade out
  79.             leds[i].fadeToBlackBy(brightness);        // Fade in
  80.         }
  81.         FastLED.show();
  82.         delay(50);
  83.     }
  84. }
  85.  
  86. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement