Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define LED_TYPE NEOPIXEL
- #define NUM_STRIPS 6 // Total number of strips
- #define NUM_LEDS0 11 // Specify length of each strip
- #define NUM_LEDS1 13
- #define NUM_LEDS2 17
- #define NUM_LEDS3 20
- #define NUM_LEDS4 21
- #define NUM_LEDS5 23
- #define TOTAL_LEDS 105
- #define BRIGHTNESS 20
- #define FRAMES_PER_SECOND 240
- #define COOLING 55
- #define SPARKING 120
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- //etc.
- CRGB leds[NUM_STRIPS][NUM_LEDS0 + NUM_LEDS1 + NUM_LEDS2 + NUM_LEDS3 + NUM_LEDS4 + NUM_LEDS5]; // Add all together here
- uint8_t stripLength; // Used to store a strip length.
- uint8_t chanceOfGlitter = 80;
- bool gReverseDirection = false;
- //---------------------------------------------------------------
- void setup() {
- Serial.begin(115200); // Allows serial monitor output (check baud rate)
- delay(3000);
- FastLED.addLeds<LED_TYPE, 6>(leds[0], NUM_LEDS0); // Assign data pins
- FastLED.addLeds<LED_TYPE, 9>(leds[1], NUM_LEDS1);
- FastLED.addLeds<LED_TYPE, 10>(leds[2], NUM_LEDS2);
- FastLED.addLeds<LED_TYPE, 11>(leds[3], NUM_LEDS3);
- FastLED.addLeds<LED_TYPE, 12>(leds[4], NUM_LEDS4);
- FastLED.addLeds<LED_TYPE, 13>(leds[5], NUM_LEDS5);
- FastLED.setBrightness( BRIGHTNESS );
- }
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { sinelon, confetti, glitter, rainbow };
- 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() {
- // Call the current pattern function once, updating the 'leds' array
- gPatterns[gCurrentPatternNumber]();
- // send the 'leds' array out to the actual LED strip
- FastLED.show();
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- // do some periodic updates
- EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
- EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
- }//end main loop
- //-----function to return strip length-----
- uint8_t getStripLength(uint8_t stripNumber){
- uint8_t L;
- if (stripNumber == 0) { L = NUM_LEDS0; }
- if (stripNumber == 1) { L = NUM_LEDS1; }
- if (stripNumber == 2) { L = NUM_LEDS2; }
- if (stripNumber == 3) { L = NUM_LEDS3; }
- if (stripNumber == 4) { L = NUM_LEDS4; }
- if (stripNumber == 5) { L = NUM_LEDS5; }
- //etc.
- return L;
- }
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- void confetti(void)
- {
- // Gradiant filled with confetti
- for(uint8_t x = 0; x < NUM_STRIPS; x++) {
- stripLength = getStripLength(x);
- fill_gradient(leds[x], 0, CHSV(10,200,255), stripLength, CHSV(160,200,255), BACKWARD_HUES);
- fadeToBlackBy(leds[x], stripLength,10);
- int pos = random16(stripLength);
- leds[x][pos]+= CHSV(gHue + random8(64),200,255);
- delay(10);
- }
- }
- void glitter(void)
- {
- // Solid filled with Glitter
- for(uint8_t x = 0; x < NUM_STRIPS; x++) {
- stripLength = getStripLength(x);
- fill_solid( leds[x], stripLength, CRGB(0,50,255));
- if (random8()<chanceOfGlitter)
- {
- leds[x][random16(stripLength)] += CRGB::White;
- }
- }
- }
- void rainbow(void)
- {
- for(uint8_t x = 0; x < NUM_STRIPS; x++) {
- stripLength = getStripLength(x);
- fill_rainbow( leds[x], stripLength, -1*millis()/2, 256/stripLength );
- }
- }
- void sinelon(void)
- {
- // Sinelon
- for(uint8_t x = 1; x < NUM_STRIPS; x++) {
- stripLength = getStripLength(x);
- fill_solid(leds[0], stripLength, CHSV( gHue, 255, 192));
- fadeToBlackBy( leds[x], stripLength, 20);
- int pos = beatsin16(50,0,stripLength);
- leds[x][pos] += CHSV( gHue, 255, 192);
- }
- }
- void Fire2012()
- {
- for(uint8_t x = 0; x < NUM_STRIPS; x++) {
- // Array of temperature readings at each simulation cell
- static byte heat[stripLength];
- // Step 1. Cool down every cell a little
- for( int i = 0; i < stripLength; i++) {
- heat[x][i] = qsub8( heat[x][i], random8(0, ((COOLING * 10) / stripLength) + 2));
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for( int k= stripLength - 1; k >= 2; k--) {
- heat[x][k] = (heat[x][k - 1] + heat[x][k - 2] + heat[x][k - 2] ) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if( random8() < SPARKING ) {
- int y = random8(7);
- heat[x][y] = qadd8( heat[x][y], random8(160,255) );
- }
- // Step 4. Map from heat cells to LED colors
- for( int j = 0; j < stripLength; j++) {
- CRGB color = HeatColor( heat[x][j]);
- int pixelnumber;
- if( gReverseDirection ) {
- pixelnumber = (stripLength-1) - j;
- } else {
- pixelnumber = j;
- }
- leds[x][pixelnumber] = color;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment