Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Marc Miller, Oct 2017
- #include "FastLED.h"
- #define NUM_LEDS 10 //216
- #define NUM_LEDS_REAL 10 //192
- #define DATA_PIN 17 //5
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- #define STRIP_EVEN 14
- #define STRIP_ODD 10
- #define BRIGHTNESS 96
- #define FRAMES_PER_SECOND 120
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- #define UPDATES_PER_SECOND 1000
- uint8_t I = 10, J=14;
- uint8_t START1 = 0, END1 = I-1;
- uint8_t START2 = START1+I, END2 = END1+J;
- uint8_t START3 = START2+J, END3 = END2+I;
- uint8_t START4 = START3+I, END4 = END3+J;
- uint8_t START5 = START4+J, END5 = END4+I;
- uint8_t START6 = START5+I, END6 = END5+J;
- uint8_t START7 = START6+J, END7 = END6+I;
- uint8_t START8 = START7+I, END8 = END7+J;
- uint8_t START9 = START8+J, END9 = END8+I;
- uint8_t START10 = START9+I, END10 = END9+J;
- uint8_t START11 = START10+J, END11 = END10+I;
- uint8_t START12 = START11+I, END12 = END11+J;
- uint8_t START13 = START12+J, END13 = END12+I;
- uint8_t START14 = START13+I, END14 = END13+J;
- uint8_t START15 = START14+J, END15 = END14+I;
- uint8_t START16 = START15+I, END16 = END15+J;
- uint8_t STARTO = START16+J, ENDO = END16+I;
- uint8_t STARTE = STARTO+I, ENDE = ENDO+J;
- int MyDelay = 200;
- uint8_t spacer = 4;
- int MyColor = 0;
- uint16_t holdTime = 300; // Milliseconds to hold position before advancing.
- uint8_t spacing = 4; // Sets pixel spacing. [Use 2 or greater]
- int8_t delta = 1; // Sets forward or backwards direction amount. (Can be negative.)
- uint8_t width = 2; // Can increase the number of pixels (width) of the chase. [1 or greater]
- boolean fadingTail = 0; // Add fading tail? [1=true, 0=false]
- uint8_t fadeRate = 150; // How fast to fade out tail. [0-255]
- uint8_t hue = 60; // Starting color.
- uint8_t hue2_shift = 50; // Hue shift for secondary color. Use 0 for no shift. [0-255]
- boolean DEBUG = 1; // Print some info to serial monitor. [1=true, 0=falue]
- int16_t pos; // Pixel position.
- int8_t advance; // Stores the advance amount.
- uint8_t color; // Stores a hue color.
- //CRGB leds[NUM_LEDS]; // Not using this. Using CRGBArray instead.
- CRGBArray<NUM_LEDS> leds;
- CRGBSet part1(leds(START1,END1));
- CRGBSet part2(leds(START2,END2));
- CRGBSet part3(leds(START3,END3));
- CRGBSet part4(leds(START4,END4));
- CRGBSet part5(leds(START5,END5));
- CRGBSet part6(leds(START6,END6));
- CRGBSet part7(leds(START7,END7));
- CRGBSet part8(leds(START8,END8));
- CRGBSet part9(leds(START9,END9));
- CRGBSet part10(leds(START10,END10));
- CRGBSet part11(leds(START11,END11));
- CRGBSet part12(leds(START12,END12));
- CRGBSet part13(leds(START13,END13));
- CRGBSet part14(leds(START14,END14));
- CRGBSet part15(leds(START15,END15));
- CRGBSet part16(leds(START16,END16));
- CRGBSet tempOdd(leds(STARTO,ENDO));
- CRGBSet tempEven(leds(STARTE,ENDE));
- uint8_t counter = 0;
- CRGBPalette16 currentPalette;
- TBlendType currentBlending;
- extern CRGBPalette16 Anjunabeach;
- extern const TProgmemPalette16 Anjunabeach_p PROGMEM;
- //---------------------------------------------------------------
- void setup() {
- delay(3000);
- FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(50);
- currentPalette = Anjunabeach_p;
- currentBlending = LINEARBLEND;
- //Serial.begin(9600);
- }
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = {
- Marquee
- /*SolidColors
- ,fillrainbow
- ,colorblocks
- ,allrainbow
- ,confetti
- ,singlerainbow
- ,swirl
- ,confetti
- ,swirlrainbow
- ,colorbars //need to fix
- //chasingdots //runs too slow
- ,PalletLoop
- ,sinelon*/
- };
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- //---------------------------------------------------------------
- void loop()
- {
- gPatterns[gCurrentPatternNumber]();
- FastLED.show();
- FastLED.delay(1000/FRAMES_PER_SECOND);
- // do some periodic updates
- EVERY_N_SECONDS( 60 ) { nextPattern(); } // change patterns periodically
- }
- void fillrainbow()
- {
- fill_rainbow(part2, STRIP_EVEN, millis()/20);
- fill_solid(part1, STRIP_ODD, CHSV(138,255,255));
- dupe();
- }
- void allrainbow()
- {
- fill_rainbow(part1, STRIP_ODD, millis()/20);
- fill_rainbow(part2, STRIP_EVEN, millis()/20);
- dupe();
- }
- void singlerainbow()
- {
- fill_rainbow(leds,NUM_LEDS_REAL,millis()/20);
- FastLED.show();
- }
- void colorblocks()
- {
- int MyColor = (random16(0,255));
- int MyHue = (random16(125,255));
- fill_solid(part1, STRIP_ODD, CHSV(MyColor,255,255));
- fill_solid(part2, STRIP_EVEN, CHSV((MyColor-125)%255,255,255));
- dupe();
- delay(500);
- }
- void colorbars()
- {
- int MyColor = (random16(0,255));
- fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
- fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
- part1 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part2 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part3 = part1;
- MyColor = (random16(0,255));
- fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
- fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
- part1 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part4 = part2;
- part2 = tempEven;
- FastLED.show();
- delay(MyDelay);
- for (uint8_t x = 0; x<10; x++)
- {
- MyColor = (random16(0,255));
- fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
- fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
- part15 = part13;
- part13 = part11;
- part11 = part9;
- part9 = part7;
- part7 = part5;
- part5 = part3;
- part3 = part1;
- part1 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part16=part14;
- part14 = part12;
- part12 = part10;
- part10 = part8;
- part8 = part6;
- part6 = part4;
- part4 = part2;
- part2 = tempEven;
- FastLED.show();
- delay(MyDelay);
- MyColor = (random16(0,255));
- fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,255,255)); //SET TEMP EVEN STRIP
- fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,255,255)); //SET TEMP ODD STRIP
- part15 = part13;
- part13 = part11;
- part11 = part9;
- part9 = part7;
- part7 = part5;
- part5 = part3;
- part3 = part1;
- part1 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part16=part14;
- part14 = part12;
- part12 = part10;
- part10 = part8;
- part8 = part6;
- part6 = part4;
- part4 = part2;
- part2 = tempEven;
- FastLED.show();
- delay(MyDelay);
- }
- }
- void dupe()
- {
- part3 = part1; //creates dupicate copy in second half of strip
- part4 = part2;
- part5 = part1;
- part6 = part2;
- part7 = part1;
- part8 = part2;
- part9 = part1;
- part10 = part2;
- part11 = part1;
- part12 = part2;
- part13 = part1;
- part14 = part2;
- part15 = part1;
- part16 = part2;
- FastLED.show();
- }
- void chasingdots()
- {
- for(uint8_t x = NUM_LEDS_REAL -1; x>0; x--)
- {
- leds[x]=leds[x-1];
- FastLED.show();
- }
- uint8_t R = random8(100);
- uint8_t c = (counter % spacer);
- if (c==0)
- {
- leds[0] = CHSV(random16(128,235),random16(128,235),255);
- }
- else
- {
- leds[0] = CHSV(0,0,0);
- }
- counter++;
- }
- void swirl()
- {
- int MyColor = random16(0,255);
- for(uint8_t loop = 0; loop<24; loop++)
- {
- for(uint8_t y = 23-loop; y<NUM_LEDS_REAL; y=y+24)
- {
- leds[y] = CHSV(MyColor,255,255);
- FastLED.show();
- }
- }
- }
- void swirlrainbow()
- {
- fill_solid(leds, NUM_LEDS_REAL, CRGB::Black);
- //uint8_t MyColor = 0;
- for(uint8_t loop = 0; loop<24; loop++)
- {
- MyColor = MyColor + (255/24);
- for(uint8_t y = 23-loop; y<NUM_LEDS_REAL; y=y+24)
- {
- leds[y] = CHSV(MyColor,255,255);
- FastLED.show();
- }
- }
- }
- void confetti()
- {
- // random colored speckles that blink in and fade smoothly
- fadeToBlackBy( leds, NUM_LEDS_REAL, 10);
- int pos = random16(NUM_LEDS_REAL);
- leds[pos] += CHSV( gHue + random16(255), 200, 255);
- FastLED.show();
- }
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS_REAL, 1);
- int pos = beatsin16( 5, 0, NUM_LEDS_REAL-1 );
- leds[pos] += CHSV( gHue, 255, 255);
- }
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- const TProgmemPalette16 myAnjunaColors_p PROGMEM =
- {
- CRGB::Red,
- CRGB::Gray, // 'white' is too bright compared to red and blue
- CRGB::Blue,
- CRGB::Black,
- CRGB::Red,
- CRGB::Gray,
- CRGB::Blue,
- CRGB::Black,
- CRGB::Red,
- CRGB::Red,
- CRGB::Gray,
- CRGB::Gray,
- CRGB::Blue,
- CRGB::Blue,
- CRGB::Black,
- CRGB::Black
- };
- void FillLEDsFromPaletteColors(uint8_t colorIndex)
- {
- uint8_t brightness = 255;
- for( int i = 0; i < NUM_LEDS_REAL; i++) {
- leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
- colorIndex += 3;
- }
- FastLED.show();
- }
- void PalletLoop()
- {
- //ChangePalettePeriodically();
- static uint8_t startIndex = 0;
- startIndex = startIndex + 10; /* motion speed */
- FillLEDsFromPaletteColors( startIndex);
- FastLED.show();
- FastLED.delay(2000 / UPDATES_PER_SECOND);
- }
- void SolidColors()
- {
- int MyDelay = 40;
- int MyColor = random16(15,64);
- int MyHue = random16(175,255);
- fill_solid(tempEven, STRIP_EVEN,CHSV(MyColor,MyHue,255)); //SET TEMP EVEN STRIP
- fill_solid(tempOdd, STRIP_ODD, CHSV(MyColor,MyHue,255)); //SET TEMP ODD STRIP
- part4 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part5 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part6 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part7 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part8 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part9 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part10 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part11 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part12 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part13 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part14 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part15 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part16 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part1 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- part2 = tempEven;
- FastLED.show();
- delay(MyDelay);
- part3 = tempOdd;
- FastLED.show();
- delay(MyDelay);
- }
- void Marquee() {
- EVERY_N_MILLISECONDS(holdTime){ // Advance pixels to next position.
- if (DEBUG==1) { // Print out some info if DEBUG is true.
- Serial.print("delta: "); Serial.print(delta);
- Serial.print(" spacing: "); Serial.print(spacing); Serial.print(" ");}
- for (uint8_t i=0; i<(NUM_LEDS_REAL/spacing); i++){
- for (uint8_t w = 0; w<width; w++){
- pos = (spacing * (i-1) + spacing + advance + w) % NUM_LEDS_REAL;
- if ( w % 2== 0 ){ // Is w even or odd?
- color = hue;
- } else {
- color = hue + hue2_shift;
- }
- leds[pos] = CHSV(color,255,255);
- }
- if (DEBUG==1) { // Print out lit pixels if DEBUG is true.
- Serial.print(" "); Serial.print(pos);
- }
- }
- if (DEBUG==1) { Serial.println(" "); }
- FastLED.show();
- // Fade out tail or set back to black for next loop around.
- if (fadingTail == 1) {
- fadeToBlackBy(leds, NUM_LEDS_REAL,fadeRate);
- } else {
- for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){
- for (uint8_t w = 0; w<width; w++){
- pos = (spacing * (i-1) + spacing + advance + w) % NUM_LEDS;
- leds[pos] = CRGB::Black;
- }
- }
- }
- // Advance pixel postion down strip, and rollover if needed.
- advance = (advance + delta + NUM_LEDS_REAL) % NUM_LEDS_REAL;
- }
- }
- const TProgmemPalette16 Anjunabeach_p PROGMEM =
- {
- CRGB::Red,
- CRGB::Orange, // 'white' is too bright compared to red and blue
- CRGB::Yellow,
- CRGB::Black,
- CRGB::Red,
- CRGB::Orange,
- CRGB::Yellow,
- CRGB::Black
- // CRGB::Red,
- // CRGB::Red,
- // CRGB::Orange,
- // CRGB::Orange,
- // CRGB::Yellow,
- // CRGB::Yellow,
- // CRGB::Blue,
- // CRGB::Blue
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement