Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fill_up_strip
- // Moving pixels "fill" up strip, then clear and start again.
- // The "filling" effect can be visually adjusted and slowed down near end.
- // Has not been tested with a large number of pixels.
- //
- // Marc Miller, Oct 2015
- //---------------------------------------------------------------
- #include "FastLED.h"
- #define LED_TYPE WS2812B
- #define DATA_PIN 6
- #define CLOCK_PIN 13
- #define NUM_LEDS 22
- #define COLOR_ORDER GRB
- #define MASTER_BRIGHTNESS 50
- CRGB leds[NUM_LEDS];
- float delta;
- uint8_t count = 0;
- uint8_t hue = 0; // Pick a random color.
- uint8_t sat = random8(160,255); // Pick a random saturation in range.
- // Mess with these values for fill speed and slowing effect.
- uint8_t fill_delay = 20; // Increase to slow fill rate.
- float delay_base = 1; // Used to add a delay as strip fills up.
- float delay_multiplier = 1; // Used to add a delay as strip fills up.
- /* Set delays to 1.0 if you don't want any slowing. These numbers need to
- be tuned visually based on your preference and also based on the number
- of pixels in your strip.
- These values looked good to me with a 32 pixel strip. Small changes can
- make a large difference so try small increments.
- */
- //---------------------------------------------------------------
- void setup() {
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness(MASTER_BRIGHTNESS);
- Serial.begin(9600); // Allows serial monitor output (check baud rate)
- }
- //---------------------------------------------------------------
- void loop() {
- long ledcolor=255/(NUM_LEDS);
- // Draw the moving pixels.
- for (int i=NUM_LEDS; i >= count; i--){
- leds[i] = CHSV(hue,255,255);
- FastLED.show();
- delay(fill_delay); // Slow things down just a bit.
- leds[i] = CRGB::Black;
- Serial.print("i = "); Serial.print(i);Serial.print(" Count = ");Serial.println(count);
- }
- // Add the new filled pixels.
- leds[count] = CHSV(hue,255,255);
- Serial.println("Place last pixel");
- FastLED.show();
- count++;
- // Delay the filling effect to slow near end.
- delta = (pow(delay_base, count) * delay_multiplier); // Delta increases as strip fills up.
- delay(delta); // Delay can increase as strip fills up.
- // Uncomment to help visualize the increasing delay.
- //Serial.print(" count:"); Serial.print(count); Serial.print(" delta: "); Serial.println(delta);
- hue = hue + ledcolor;
- // Clear the strip when full.
- if (count == NUM_LEDS){
- Serial.println(" -------- Reset! --------");
- delay(1400); // Hold filled strip for a moment.
- FastLED.clear(); // Blank out the strip data.
- FastLED.show();
- count = 0; // Reset count.
- hue = hue + ledcolor; // Pick a new random fill color.
- sat = random8(160,255); // Pick a random saturation in range.
- delay(700); // Breif pause before filling again.
- }
- } //end main loop
Advertisement
Add Comment
Please, Sign In to add comment