Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_STRIPS 2
- #define NUM_SPOKES 6
- #define NUM_LEDS_PER_STRIPE 15
- #define NUM_LEDS_PER_SPOKE 25
- #define TTL_LEDS NUM_SPOKES * NUM_LEDS_PER_SPOKE
- // #define TTL_LEDS 50
- CRGB leds[NUM_SPOKES][NUM_LEDS_PER_SPOKE];
- #define NUM_LEDS_MAIN 15
- #define ARM1_OFFSET 6
- #define ARM1_LENGTH 2
- #define ARM2_OFFSET 12
- #define ARM2_LENGTH 3
- // Create array values for lighting arm spots identically to stripe spots.
- // If arms are made longer, additional lines must be coded to fill them.
- unsigned char armLedEquivs[5][3] = {{ARM1_OFFSET, NUM_LEDS_MAIN + ARM2_LENGTH * 2, NUM_LEDS_MAIN + ARM2_LENGTH * 2 + ARM1_LENGTH},
- {ARM1_OFFSET + 1, NUM_LEDS_MAIN + ARM2_LENGTH * 2 + 1, NUM_LEDS_MAIN + ARM2_LENGTH * 2 + ARM1_LENGTH + 1},
- {ARM2_OFFSET, NUM_LEDS_MAIN, NUM_LEDS_MAIN + ARM2_LENGTH},
- {ARM2_OFFSET + 1, NUM_LEDS_MAIN + 1, NUM_LEDS_MAIN + ARM2_LENGTH + 1},
- {ARM2_OFFSET + 2, NUM_LEDS_MAIN + 2, NUM_LEDS_MAIN + ARM2_LENGTH + 2}};
- #define SWT_BRIGHTNESS 220
- #define SWT_DENSITY 220
- #define RM_BRIGHTNESS 200
- unsigned long startTime;
- unsigned long endTime;
- uint8_t lastSelection = 255; // last effect used
- uint8_t currSelection = 16; // next effect to use
- CRGBPalette16 currentPalette;
- // TBlendType currentBlending;
- // currentBlending = BLEND;
- CRGB red = CHSV( HUE_RED, 255, 255 );
- CRGB green = CHSV( HUE_GREEN, 255, 255 );
- CRGB blue = CHSV( HUE_BLUE, 255, 255 );
- CRGB yellow = CHSV( HUE_YELLOW, 255, 255 );
- CRGB purple = CHSV( HUE_PURPLE, 255, 255 );
- CRGB colorArray[] = {red, green, blue, yellow, purple, CRGB::White};
- void setup() {
- FastLED.addLeds<WS2812B, 12, GRB>(leds[0], NUM_LEDS_PER_SPOKE * NUM_SPOKES).setCorrection( TypicalLEDStrip );
- set_max_power_in_volts_and_milliamps(5, 11000); // FastLED 2.1 Power management set at 5V, 11A
- BlankTheSnowflake();
- }
- void loop() {
- while( currSelection != lastSelection ) {
- lastSelection = currSelection;
- switch( currSelection ) {
- case 0:
- RotateThroughColorWheel( 60, 48, 200 );
- break;
- case 1:
- RainbowMarquee( 30, 0, 64, 20, 1, 40 ); // pulsing primary spots
- break;
- case 2:
- GrowAndCycle( 30, 3 );
- break;
- case 3:
- GrowFadeCycle( 30, 5 );
- break;
- case 4:
- RainbowMarquee( 30, 0, 20, 10, 0, 40 ); // smooth tie-dye effect
- break;
- case 5:
- SoftWarmTwinkles( 60 );
- break;
- case 6:
- PopFade( 15 ); // multi-color fast blink spots
- break;
- case 7:
- Sparkle( 15, CRGB::White, 5, 6 ); // all white, dense fast blink spots
- break;
- case 8:
- Sparkle( 15, CRGB::Blue, 3, 4 ); // all blue, medium density fast blink spots
- break;
- case 9:
- Sparkle( 15, CRGB::Red, 3, 4 ); // all red, medium density fast blink spots
- break;
- case 10:
- Sparkle( 15, CRGB::Green, 3, 4 ); // all green, medium density fast blink spots
- break;
- case 11:
- Sparkle( 15, CRGB::Purple, 3, 4 ); // all purple, medium density fast blink spots
- break;
- case 12:
- RedGreenRandom( 30 );
- break;
- case 13:
- MultiMeteor( 30, false );
- break;
- case 14:
- MultiMeteor( 30, true ); // true = green background with only red meteors
- break;
- case 15:
- SpiralOut( 60 );
- break;
- case 16:
- SpiralIn( 45 );
- break;
- }
- FadeTheSnowflake();
- BlankTheSnowflake();
- FastLED.setBrightness( 255 );
- }
- currSelection = random8( 17 );
- }
- void SpiralIn(unsigned long duration) {
- CRGB holdStripe[NUM_LEDS_PER_SPOKE];
- for( int y = 0; y < NUM_LEDS_PER_STRIPE; y++ ) {
- for( int x = 0; x < NUM_SPOKES; x++ ) {
- leds[x][y] = colorArray[(x + y)%6];
- }
- }
- for( int x = 0; x < NUM_SPOKES; x++ ) {
- setArmsToStripe( x );
- }
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- memcpy8( &holdStripe[0], &leds[0][0], NUM_LEDS_PER_SPOKE * 3);
- for( int i = 1; i < NUM_SPOKES; i++ ) {
- memcpy8( &leds[i - 1][0], &leds[i][0], NUM_LEDS_PER_SPOKE * 3);
- }
- memcpy8( &leds[NUM_SPOKES - 1][0], &holdStripe[0], NUM_LEDS_PER_SPOKE * 3 );
- FastLED.show();
- delay(100);
- }
- }
- void SpiralOut(unsigned long duration) {
- uint8_t cycle = 0;
- CRGB holdStripe[NUM_LEDS_PER_STRIPE];
- currentPalette = RainbowColors_p;
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- memcpy8( &holdStripe[0], &leds[0][0], NUM_LEDS_PER_STRIPE * 3);
- for( int i = 1; i < NUM_SPOKES; i++ ) {
- memcpy8( &leds[i - 1][0], &leds[i][0], NUM_LEDS_PER_STRIPE * 3);
- }
- memcpy8( &leds[NUM_SPOKES - 1][1], &holdStripe[0], (NUM_LEDS_PER_STRIPE - 1) * 3 );
- leds[NUM_SPOKES - 1][0] = ColorFromPalette( currentPalette, cycle, 220, NOBLEND);
- FastLED.show();
- delay(10);
- cycle++;
- }
- }
- void MultiMeteor(unsigned long duration, boolean doRedGreen) {
- uint8_t hue[] = {32, 128, 224, 64, 160, 192};
- int idex[] = {255, -29, -10, -17, -3, -21};
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- for( int i = 0; i < NUM_SPOKES; i++ ) {
- // slide all the pixels in the stripe down one
- memmove8( &leds[i][1], &leds[i][0], (NUM_LEDS_PER_STRIPE - 1) * 3 );
- // increment the meteor display frame
- idex[i]++;
- // make sure we don't drift into space
- if( idex[i] > 29 ) {
- idex[i] = 0;
- // cycle through hues in each successive meteor tail
- hue[i] += 32;
- }
- if( doRedGreen ) {
- hue[i] = 32;
- }
- if( idex[i] > -1 ) {
- // this switch controls the actual meteor animation, i.e., what gets placed in the
- // first position and then subsequently gets moved down the strip by the memmove above
- switch ( idex[i] ) {
- case 0:
- leds[i][0] = CRGB(200,200,200);
- break;
- case 1:
- leds[i][0] = CHSV((hue[i] - 20), 255, 210);
- break;
- case 2:
- leds[i][0] = CHSV((hue[i] - 22), 255, 180);
- break;
- case 3:
- leds[i][0] = CHSV((hue[i] - 23), 255, 150);
- break;
- case 4:
- leds[i][0] = CHSV((hue[i] - 24), 255, 110);
- break;
- case 5:
- leds[i][0] = CHSV((hue[i] - 25), 255, 90);
- break;
- case 6:
- leds[i][0] = CHSV((hue[i] - 26), 160, 60);
- break;
- case 7:
- leds[i][0] = CHSV((hue[i] - 27), 140, 40);
- break;
- case 8:
- leds[i][0] = CHSV((hue[i] - 28), 120, 20);
- break;
- case 9:
- leds[i][0] = CHSV((hue[i] - 29), 100, 20);
- break;
- default:
- if( doRedGreen ) {
- leds[i][0] = green;
- } else {
- leds[i][0] = CRGB::Black;
- }
- }
- }
- setArmsToStripe( i );
- }
- // show the blinky
- FastLED.show();
- // control the animation speed/frame rate
- delay(30);
- }
- }
- void RedGreenRandom(unsigned long duration) {
- const CRGB colors[] = { red, green, CRGB::Black };
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- for( int i = 0; i < 3; i++ ) {
- *((CRGB *)leds + random8( TTL_LEDS )) = colors[i];
- }
- FastLED.show();
- delay( 30 );
- }
- }
- void Sparkle(unsigned long duration, CRGB color, uint8_t turnOn, uint8_t turnOff) {
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- for( int i = 0; i < turnOn; i++ ) {
- *((CRGB *)leds + random8( TTL_LEDS )) = color;
- }
- FastLED.show();
- for( int i = 0; i < turnOff; i++ ) {
- *((CRGB *)leds + random8( TTL_LEDS )) = CRGB::Black;
- }
- }
- }
- void RainbowMarquee(unsigned long duration, uint8_t thishue, uint8_t deltahue,
- int8_t thisrot, bool thisdir, uint8_t thisdelay) {
- // adapted from code by Andrew Tuline
- // Oct, 2014
- FastLED.setBrightness( RM_BRIGHTNESS );
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- if ( thisdir == 0 ) thishue += thisrot; else thishue-= thisrot; // I could use signed math, but 'thisdir' works with other routines.
- fill_rainbow( &leds[0][0], TTL_LEDS, thishue, deltahue ); // I don't change deltahue on the fly as it's too fast near the end of the strip.
- show_at_max_brightness_for_power(); // Power managed display of LED's.
- delay_at_max_brightness_for_power( 2.5*thisdelay ); // Power managed FastLED delay.
- }
- }
- void SoftWarmTwinkles(unsigned long duration) {
- // By: Mark Kriegsman (modified)
- // www.fastled.io
- // Date: December 2014
- // For this animation to work, the Red component of this
- // color MUST be nonzero, AND must be an EVEN number.
- const CRGB lightcolor(8,7,1);
- BlankTheSnowflake();
- FastLED.setBrightness(SWT_BRIGHTNESS);
- uint8_t spoke;
- uint8_t pixel;
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- for( int y = 0; y < NUM_LEDS_PER_SPOKE; y++) {
- for( int x = 0; x < NUM_SPOKES; x++) {
- if( !leds[x][y]) continue; // skip black pixels
- if( leds[x][y].r & 1) { // is red odd?
- leds[x][y] -= lightcolor; // darken if red is odd
- } else {
- leds[x][y] += lightcolor; // brighten if red is even
- }
- }
- }
- // Randomly choose a pixel, and if it's black, 'bump' it up a little.
- // Since it will now have an EVEN red component, it will start getting
- // brighter over time.
- for( int a = 0; a < 5; a++) {
- if( random8() < SWT_DENSITY) {
- int j = random16(TTL_LEDS);
- spoke = (j)/NUM_LEDS_PER_SPOKE;
- pixel = (j)%NUM_LEDS_PER_SPOKE;
- if( !leds[spoke][pixel] ) leds[spoke][pixel] = lightcolor;
- }
- }
- FastLED.show();
- FastLED.delay(20);
- }
- }
- void PopFade(unsigned long duration) {
- // By: Andrew Tuline (modified)
- // www.tuline.com
- // Date: Sep, 2014
- int ranamount = 150; // The higher the number, lowers the chance for a pixel to light up.
- uint8_t thisdelay = 50; // Standard delay value.
- bool boolcolours = 0; // True = random, False = array of colours (up to 10)
- uint8_t numcolours = 4; // Number of colours in the array to display.
- unsigned long colours[10] = {0xff0000, 0x00ff00, 0x0000ff, 0xffffff}; // Just assign the first 3 of these selectable colours.
- uint8_t maxbar = 1; // Maximum # of pixels to turn on in a row
- uint8_t fadeval = 224; // Fade rate
- unsigned long thiscolour;
- uint8_t spoke;
- uint8_t pixel;
- // thisdelay = 50; colours[0] = 0xffffff; numcolours=1; boolcolours=0; maxbar = 1;
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- int idex = random16( 0, ranamount );
- if ( idex < TTL_LEDS ) { // Only the lowest probability twinkles will do.
- boolcolours ? thiscolour = random(0, 0xffffff) : thiscolour = colours[random16(0, numcolours)];
- int barlen = random16( 1,maxbar );
- for ( int i = 0; i < barlen; i++ )
- if ( idex+i < TTL_LEDS ) {
- spoke = (idex+i)/NUM_LEDS_PER_SPOKE;
- pixel = (idex+i)%NUM_LEDS_PER_SPOKE;
- leds[spoke][pixel] = thiscolour; // Make sure we don't overshoot the array.
- }
- }
- for ( spoke = 0; spoke < NUM_SPOKES; spoke++) {
- for ( pixel = 0; pixel < NUM_LEDS_PER_SPOKE; pixel++ ) {
- leds[spoke][pixel].nscale8(fadeval); // Go through the array and reduce each RGB value by a percentage.
- }
- }
- FastLED.show();
- }
- }
- // Starting at the center, fill the leds outward, cycling through up to five colors
- void GrowFadeCycle(unsigned long duration, int nbrColors) {
- uint8_t currColor = 0;
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- GrowSimultaneous( colorArray[currColor], 100 );
- currColor++;
- currColor = currColor%nbrColors;
- delay(600);
- FadeTheSnowflake();
- }
- }
- // Starting at the center, fill the leds outward, cycling through up to five colors
- void GrowAndCycle(unsigned long duration, int nbrColors) {
- uint8_t currColor = 0;
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- GrowSimultaneous( colorArray[currColor], 100 );
- currColor++;
- currColor = currColor%nbrColors;
- delay(300);
- }
- }
- void GrowSimultaneous(CRGB color, int pause) {
- // This outer loop will cycle through each led in the spoke
- for( int y = 0; y < NUM_LEDS_PER_STRIPE; y++ ) {
- // This inner loop will cycle through each spoke
- for( int x = 0; x < NUM_SPOKES; x++ ) {
- leds[x][y] = color;
- setArmsToStripe(x);
- }
- FastLED.show();
- delay(pause);
- }
- }
- void UngrowSimultaneous(CRGB color, int pause) {
- // This outer loop will cycle through each led in the spoke
- for( int y = NUM_LEDS_PER_STRIPE - 1; y > - 1; y-- ) {
- // This inner loop will cycle through each spoke
- for( int x = 0; x < NUM_SPOKES; x++ ) {
- leds[x][y] = color;
- setArmsToStripe(x);
- }
- FastLED.show();
- delay(pause);
- }
- }
- // This function cycles through the color wheel palette.
- // "duration" specifies number of seconds to run the routine
- // "simul_spokes" is either 16, 32 or 64 in order to keep
- // 3, 2 or 1 consecutive spokes the same color
- void RotateThroughColorWheel(unsigned long duration, int simul_spokes, int brightness) {
- CRGB spoke_color[7];
- SetupColorWheelPalette();
- uint8_t pri_clr_idx = 0;
- startTime = millis();
- endTime = (duration * 1000) + startTime;
- while( millis() < endTime ) {
- for( int a = 0; a < NUM_SPOKES; a++ ) {
- for( int c = 0; c < 7; c++ ) {
- spoke_color[c] = ColorFromPalette( currentPalette, pri_clr_idx + c + (simul_spokes * a), brightness, BLEND);
- }
- for( int b = 0; b < NUM_LEDS_PER_STRIPE; b++ ) {
- leds[a][b] = spoke_color[3];
- }
- // for( int d = 0; d < 5; d++ ) {
- // armLedEquivs
- leds[a][17] = spoke_color[0];
- leds[a][16] = spoke_color[1];
- leds[a][15] = spoke_color[2];
- leds[a][18] = spoke_color[4];
- leds[a][19] = spoke_color[5];
- leds[a][20] = spoke_color[6];
- leds[a][22] = spoke_color[1];
- leds[a][21] = spoke_color[2];
- leds[a][23] = spoke_color[4];
- leds[a][24] = spoke_color[5];
- // }
- }
- FastLED.show();
- pri_clr_idx++;
- delay(100);
- }
- }
- // This function sets up the colorwheel palette.
- void SetupColorWheelPalette() {
- currentPalette = CRGBPalette16(
- red, red, red, blue,
- blue, blue, blue, yellow,
- yellow, yellow, yellow, green,
- green, green, green, red );
- }
- // Turn off all lights in the snowflake immediately
- void BlankTheSnowflake() {
- FastLED.clear();
- }
- // Turn off all lights in the snowflake gradually
- void FadeTheSnowflake() {
- for( int a = 0; a < 30; a++ ) {
- // fadeToBlackBy( &leds[0][0], NUM_LEDS_PER_SPOKE * NUM_SPOKES, 40 );
- fadeToBlackBy( &leds[0][0], TTL_LEDS, 40 );
- FastLED.show();
- delay(40);
- }
- }
- // Set the side arm spots to the same value as the stripe spot at that distance
- // using the table established above.
- void setArmsToStripe(int x) {
- for(unsigned char b = 0; b < 5; b++) {
- leds[x][armLedEquivs[b][1]] = leds[x][armLedEquivs[b][0]];
- leds[x][armLedEquivs[b][2]] = leds[x][armLedEquivs[b][0]];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment