Advertisement
pleasedontcode

FastLED Control rev_05

May 1st, 2024
83
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: FastLED Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-01 09:51:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The LED chipset is WS2812B RGB  Number of LED is */
  21.     /* 20  Digital output is D5  all 20 led fade in and */
  22.     /* out slowly and randomly.  set fade in value at 0, */
  23.     /* set fade out value at 255  use all colors randomly */
  24.     /* for each led and */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <FastLED.h>    //https://github.com/FastLED/FastLED
  29.  
  30. const uint8_t NUM_LEDS = 20; // Number of WS2812B RGB LEDs
  31. const uint8_t WS2812B_LEDRGB_PIN = 5; // Digital output pin for WS2812B LEDs
  32.  
  33. CRGB leds[NUM_LEDS]; // Define the LED array
  34.  
  35. void setup(void)
  36. {
  37.     // put your setup code here, to run once:
  38.     FastLED.addLeds<WS2812B, WS2812B_LEDRGB_PIN, GRB>(leds, NUM_LEDS);
  39. }
  40.  
  41. void loop(void)
  42. {
  43.     // put your main code here, to run repeatedly:
  44.     fadeInOutRandomColors();
  45. }
  46.  
  47. void fadeInOutRandomColors()
  48. {
  49.     for (int i = 0; i < NUM_LEDS; i++) {
  50.         leds[i] = CRGB(0, 0, 0); // Initialize LED color to off
  51.     }
  52.  
  53.     while (true) {
  54.         for (int i = 0; i < NUM_LEDS; i++) {
  55.             leds[i].fadeToBlackBy(5); // Fade out LED color
  56.         }
  57.  
  58.         int ledIndex = random8(NUM_LEDS); // Select a random LED
  59.         leds[ledIndex] = CRGB(random8(), random8(), random8()); // Set random color to the selected LED
  60.         leds[ledIndex].fadeToBlackBy(-5); // Fade in LED color
  61.  
  62.         FastLED.show();
  63.         delay(50); // Adjust the delay time for fade effect
  64.     }
  65. }
  66.  
  67. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement