Guest User

Untitled

a guest
Jan 7th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. // fill_up_strip
  2. // Moving pixels "fill" up strip, then clear and start again.
  3. // The "filling" effect can be visually adjusted and slowed down near end.
  4. // Has not been tested with a large number of pixels.
  5. //
  6. // Marc Miller,  Oct 2015
  7. //---------------------------------------------------------------
  8.  
  9. #include "FastLED.h"
  10. #define LED_TYPE WS2812B
  11. #define DATA_PIN 6
  12. #define CLOCK_PIN 13
  13. #define NUM_LEDS 22
  14. #define COLOR_ORDER GRB
  15. #define MASTER_BRIGHTNESS 50
  16. CRGB leds[NUM_LEDS];
  17. float delta;
  18. uint8_t count = 0;
  19. uint8_t hue = 0;         // Pick a random color.
  20. uint8_t sat = random8(160,255);  // Pick a random saturation in range.
  21.  
  22.  
  23. // Mess with these values for fill speed and slowing effect.
  24. uint8_t fill_delay = 20;        // Increase to slow fill rate.
  25. float delay_base = 1;        // Used to add a delay as strip fills up.
  26. float delay_multiplier = 1;  // Used to add a delay as strip fills up.
  27. /*  Set delays to 1.0 if you don't want any slowing.  These numbers need to
  28.     be tuned visually based on your preference and also based on the number
  29.     of pixels in your strip.
  30.     These values looked good to me with a 32 pixel strip.  Small changes can
  31.     make a large difference so try small increments.
  32. */
  33.  
  34.  
  35. //---------------------------------------------------------------
  36. void setup() {
  37.   FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  38.   FastLED.setBrightness(MASTER_BRIGHTNESS);
  39.   Serial.begin(9600);  // Allows serial monitor output (check baud rate)
  40. }
  41.  
  42. //---------------------------------------------------------------
  43. void loop() {
  44.   long ledcolor=255/(NUM_LEDS);
  45.  
  46.   // Draw the moving pixels.
  47.   for (int i=NUM_LEDS; i >= count; i--){
  48.     leds[i] = CHSV(hue,255,255);
  49.     FastLED.show();
  50.     delay(fill_delay);  // Slow things down just a bit.
  51.     leds[i] = CRGB::Black;
  52.     Serial.print("i = "); Serial.print(i);Serial.print("     Count = ");Serial.println(count);
  53.   }
  54.  
  55.   // Add the new filled pixels.
  56.   leds[count] = CHSV(hue,255,255);
  57.   Serial.println("Place last pixel");
  58.   FastLED.show();
  59.   count++;
  60.  
  61.   // Delay the filling effect to slow near end.
  62.   delta = (pow(delay_base, count) * delay_multiplier);  // Delta increases as strip fills up.
  63.   delay(delta);  // Delay can increase as strip fills up.
  64.   // Uncomment to help visualize the increasing delay.
  65.   //Serial.print("  count:"); Serial.print(count); Serial.print("    delta: "); Serial.println(delta);
  66.  
  67.   hue = hue + ledcolor;  
  68.  
  69.   // Clear the strip when full.
  70.   if (count == NUM_LEDS){
  71.     Serial.println("    -------- Reset! --------");
  72.     delay(1400);             // Hold filled strip for a moment.
  73.     FastLED.clear();         // Blank out the strip data.
  74.     FastLED.show();
  75.     count = 0;               // Reset count.
  76.     hue = hue + ledcolor;         // Pick a new random fill color.
  77.     sat = random8(160,255);  // Pick a random saturation in range.
  78.     delay(700);              // Breif pause before filling again.
  79.   }
  80.  
  81. }  //end main loop
Advertisement
Add Comment
Please, Sign In to add comment