Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- // Pattern types supported:
- enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, COLOR_BOUNCE, SCANNER, FADE };
- // Patern directions supported:
- enum direction { FORWARD, REVERSE };
- #define NUM_LEDS 160
- #define NUM_ROWS 8
- #define NUM_LEDSPERROW 20
- CRGB leds[NUM_ROWS][NUM_LEDSPERROW];
- // NeoPattern Class - derived from the Adafruit_NeoPixel class
- class TreePatterns
- {
- public:
- // Member Variables:
- pattern ActivePattern; // which pattern is running
- direction Direction; // direction to run the pattern
- uint16_t Row; // current row/branch to work on
- uint16_t RowSize; //totan length of row
- unsigned long Interval; // milliseconds between updates
- unsigned long lastUpdate; // last update of position
- uint32_t Color1, Color2; // What colors are in use
- uint16_t TotalSteps; // total number of steps in the pattern
- uint16_t Index; // current step within the pattern
- // Constructor - calls base-class constructor to initialize strip
- TreePatterns(uint16_t row, uint16_t rownumleds)
- {
- Row = row-1;
- RowSize = rownumleds;
- }
- // Update the pattern
- void Update()
- {
- if((millis() - lastUpdate) > Interval) // time to update
- {
- lastUpdate = millis();
- switch(ActivePattern)
- {
- case RAINBOW_CYCLE:
- //RainbowCycleUpdate();
- break;
- case THEATER_CHASE:
- //TheaterChaseUpdate();
- break;
- case COLOR_WIPE:
- ColorWipeUpdate();
- break;
- case COLOR_BOUNCE:
- ColorBounceUpdate();
- break;
- case FADE:
- //FadeUpdate();
- break;
- default:
- break;
- }
- //ColorWipeUpdate();
- //ColorBounceUpdate();
- //FastLED.show();
- }
- }
- // Increment the Index and reset at the end
- void Increment()
- {
- if (Direction == FORWARD)
- {
- Index++;
- if (Index >= TotalSteps)
- {
- Index = 0;
- }
- }
- else // Direction == REVERSE
- {
- --Index;
- if (Index <= 0)
- {
- Index = TotalSteps-1;
- }
- }
- }
- // Reverse pattern direction
- void Reverse()
- {
- if (Direction == FORWARD)
- {
- Direction = REVERSE;
- Index = TotalSteps-1;
- }
- else
- {
- Direction = FORWARD;
- Index = 0;
- }
- }
- void Reflect()
- {
- if (Direction == FORWARD)
- {
- Index++;
- if (Index >= TotalSteps-1)
- {
- Direction = REVERSE;
- }
- }
- else
- {
- Index--;
- if (Index == 0)
- {
- Direction = FORWARD;
- }
- }
- }
- // Initialize for a ColorWipe
- void ColorWipe(uint32_t color, uint16_t interval,direction dir = FORWARD)
- {
- ActivePattern = COLOR_WIPE;
- Interval = interval;
- TotalSteps = RowSize;
- Color1 = color;
- Index = 0;
- Direction = dir;
- }
- // Update the Color Wipe Pattern
- void ColorWipeUpdate()
- {
- leds[Row][Index] = CRGB::Red;
- //FastLED.show();
- Increment();
- }
- // Initialize for a ColorWipe
- void ColorBounce(uint16_t interval)
- {
- ActivePattern = COLOR_BOUNCE;
- Interval = interval;
- TotalSteps = RowSize;
- Index = 0;
- }
- // Update the Color Wipe Pattern
- void ColorBounceUpdate()
- {
- for(int i = 0; i <= TotalSteps; i++ ) {
- if (i == Index) {leds[Row][i] = CHSV(100, 200, 255);}
- else {leds[Row][i] = CHSV(0, 0, 0);}
- }
- //FastLED.show();
- Reflect();
- }
- };
- TreePatterns Branch1(1, 10);
- TreePatterns Branch2(2, 8);
- TreePatterns Branch3(3, 21);
- //TreePatterns Branch4(4, 4);
- //TreePatterns Branch5(5, 5);
- //TreePatterns Branch6(6, 6);
- // Initialize everything and prepare to start
- void setup()
- {
- Serial.begin(115200);
- FastLED.addLeds<WS2812B, 2, GRB>(leds[0], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 14, GRB>(leds[1], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 7, GRB>(leds[2], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 20, GRB>(leds[3], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 6, GRB>(leds[4], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 9, GRB>(leds[5], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 21, GRB>(leds[6], NUM_LEDSPERROW);
- FastLED.addLeds<WS2812B, 5, GRB>(leds[7], NUM_LEDSPERROW);
- // Kick off a pattern
- Branch1.ColorWipe(255, 100);
- Branch2.ColorBounce(100);
- Branch3.ColorWipe(255, 200);
- //Branch4.ColorWipe(255, 1000);
- //Branch5.ColorBounce(500);
- //Branch6.ColorWipe(255, 100);
- }
- // Main loop
- void loop()
- {
- // Update the rings.
- Branch1.Update();
- Branch2.Update();
- Branch3.Update();
- //Branch4.Update();
- //Branch5.Update();
- //Branch6.Update();
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement