Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include "FastLED.h"
- FASTLED_USING_NAMESPACE
- // settings
- #define DATA_PIN 5
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define BRIGHTNESS 100
- #define PANEL_SIZE 32 // number of LEDs per panel
- #define PANEL_COUNT 8 // number of panels
- CRGBArray<PANEL_COUNT * PANEL_SIZE> ledset; // setup our LED strip array
- CRGBPalette16 colorset; // our color palette
- CRGBSet *panel[PANEL_COUNT]; // pointer for each panel
- byte colPos = 0; // our position in the color set
- byte colRng = 64; // color palette range 1-255 (color change between each panel, higher = less difference)
- int speed = 200; // change speed in ms
- void buildpal(int); // function that will build our color palettes
- void setup()
- {
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(ledset, (PANEL_COUNT * PANEL_SIZE)).setCorrection(TypicalLEDStrip);
- // create a CRGBSet for each panel
- for (byte i = 0; i < PANEL_COUNT; i++)
- {
- int sled = PANEL_SIZE * i;
- panel[i] = new CRGBSet(ledset(sled, (sled + PANEL_SIZE) - 1));
- }
- }
- void loop()
- {
- if (colPos == 0) // only build our gradiant every cycle through not every draw event
- {
- buildpal(1); // select palette
- }
- *panel[0] = ColorFromPalette(colorset, (colPos * (255 / colRng)), BRIGHTNESS); // set color of 1st panel
- FastLED.delay(speed); // draw to LEDs & delay
- // slide the LED array over by 1 panel (1 -> 2, 2 -> 3, 3 -> 4, etc.)
- memmove(&ledset[PANEL_SIZE], &ledset[0], sizeof(CRGB) * (PANEL_SIZE) * (PANEL_COUNT - 1));
- if (++colPos == colRng) // if we are at the end of our palette, start over
- {
- colPos = 0;
- }
- }
- void buildpal(int gstyle) // color palettes
- {
- switch (gstyle)
- {
- case 0: // rainbow
- colorset = RainbowColors_p;
- break;
- case 1: // party
- colorset = PartyColors_p;
- break;
- case 2: // Ocean
- colorset = OceanColors_p;
- break;
- case 3: // example of custom palette that will flow red -> blue -> red
- colorset = CRGBPalette16(CRGB::Red, CRGB::Blue, CRGB::Red);
- break;
- default: // if nothing matches return just white
- colorset = CRGBPalette16(CRGB::White);
- break;
- }
- }
Add Comment
Please, Sign In to add comment