Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************************
- // Example for Tim Lukasik based on this post:
- // https://plus.google.com/u/0/100542328320334100166/posts/51yQaDrLbBM
- //
- // This rolls my marquee example into a function that can
- // be used in Mark Kriegsman's DemoReel100 example.
- // Things needed to be reordered a bit so the show() could be
- // removed from inside the function and only have it called
- // in the main loop.
- // And all the variables were made static so they could be left
- // down below inside the function.
- //
- // Marc Miller, June 2018
- //***************************************************************
- #include <FastLED.h>
- //FASTLED_USING_NAMESPACE
- #define DATA_PIN 11
- #define CLOCK_PIN 13
- #define LED_TYPE LPD8806
- #define COLOR_ORDER GRB
- #define NUM_LEDS 32
- CRGB leds[NUM_LEDS];
- #define BRIGHTNESS 64
- #define FRAMES_PER_SECOND 120
- //---------------------------------------------------------------
- void setup() {
- Serial.begin(115200); // Allows serial monitor output (check baud rate)
- delay(500); // Startup delay
- //FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- FastLED.clear();
- }
- //---------------------------------------------------------------
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { marquee, 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( 15 ) { gHue++; } // cycle the "base color" through the rainbow
- EVERY_N_SECONDS( 60 ) { nextPattern(); } // change patterns periodically
- }//end_main_loop
- //---------------------------------------------------------------
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- //---------------------------------------------------------------
- void rainbow()
- {
- // FastLED's built-in rainbow generator
- fill_rainbow( leds, NUM_LEDS, gHue, 20);
- }
- //---------------------------------------------------------------
- void marquee() {
- const uint16_t holdTime = 700; // Milliseconds to hold position before advancing.
- static uint8_t spacing = 5; // Sets pixel spacing. [Use 2 or greater]
- static int8_t delta = 1; // Sets forward or backwards direction amount. (Can be negative.)
- static uint8_t width = 3; // Can increase the number of pixels (width) of the chase. [1 or greater]
- static boolean fadingTail = 0; // Add fading tail? [1=true, 0=falue]
- static uint8_t fadeRate = 220; // How fast to fade out tail. [0-255]
- static uint8_t hue = 180; // Starting color.
- static uint8_t hue2_shift = 20; // Hue shift for secondary color. Use 0 for no shift. [0-255]
- static int16_t pos; // Pixel position.
- static int8_t advance = -1*width; // Stores the advance amount.
- static uint8_t color; // Stores a hue color.
- EVERY_N_SECONDS(10){ // Demo: Change direction every N seconds.
- delta = -1*delta;
- }
- //EVERY_N_SECONDS(10){ // Demo: Changing the pixel spacing every N seconds.
- // spacing = spacing + 1;
- // if (spacing == 9) { spacing = 2; } // Reset spacing to 2
- // if (spacing >5) { spacing = 8; } // Jump spacing up to 8
- //}
- EVERY_N_SECONDS(10){ // Demo: Change the hue every N seconds.
- hue = hue + random8(30,61); // Shift the hue to something new.
- }
- EVERY_N_MILLISECONDS(holdTime){ // Advance pixels to next position.
- // Advance pixel postion down strip, and rollover if needed.
- advance = (advance + delta + NUM_LEDS) % NUM_LEDS;
- // Fade out tail or set back to black for next loop around.
- if (fadingTail == 1) {
- fadeToBlackBy(leds, NUM_LEDS,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 - 1) % NUM_LEDS;
- leds[pos] = CRGB::Black;
- }
- }
- }
- // Update pixels down the strip.
- 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;
- if ( w % 2== 0 ){ // Is w even or odd?
- color = hue;
- } else {
- color = hue + hue2_shift;
- }
- leds[pos] = CHSV(color,255,255);
- }
- }
- //FastLED.show(); //Not calling show here, only in main loop.
- }//end_every_n
- }//end_marquee
Advertisement
Add Comment
Please, Sign In to add comment