jahnarne

FastLED rainbow

Nov 13th, 2025
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.88 KB | Source Code | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS 30     // Number of LEDs in your strip
  4. #define DATA_PIN 6      // Data pin connected to your LED strip
  5. #define LED_TYPE WS2813 // Type of LED strip (e.g., WS2812B, NeoPixel)
  6. #define BRIGHTNESS 255  // Global brightness (0-255)
  7. #define SATURATION 255  // Global saturation (0-255)
  8.  
  9. CRGB leds[NUM_LEDS]; // Array to store LED colors
  10.  
  11. void setup() {
  12.   FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
  13.   FastLED.setBrightness(BRIGHTNESS);
  14. }
  15.  
  16. void loop() {
  17.   // Create a moving rainbow effect
  18.   for (int j = 0; j < 255; j++) { // Loop through hues
  19.     for (int i = 0; i < NUM_LEDS; i++) {
  20.       // Assign a hue based on LED position and the current 'j' value
  21.       leds[i] = CHSV(i * (255 / NUM_LEDS) + j, SATURATION, BRIGHTNESS);
  22.     }
  23.     FastLED.show(); // Update the LED strip
  24.     delay(25);      // Control animation speed
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment