Advertisement
atuline

Cylon FastLED.delay issue with FastLED 2.1

Sep 18th, 2014
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.18 KB | None | 0 0
  1. // Cylon FastLED.delay issue with FastLED 2.1
  2. //
  3. // This is modified from the FastLED Cylon example
  4. //
  5. // By: Andrew Tuline
  6. //
  7. // Date: Sep, 2014
  8. //
  9. // This demonstrates LED duty cycle issues with FastLED.delay, and a kludgy workaround.
  10. //
  11. //
  12. // Some routines, such as the Cylon example work as follows:
  13. //
  14. // - Set an LED Colour
  15. // - FastLED.show
  16. // - Clear the LED Colour
  17. // - Delay
  18. //
  19. // The problem is that with the above technique, unlike a standard delay() statement, when using FastLED.delay,
  20. // the LED's don't show for the entire delay duration. As a result, the LED's have a significantly
  21. // lower duty cycle.
  22. //
  23. // FastLED 2.1 is available at https://github.com/FastLED/FastLED/tree/FastLED2.1
  24. //
  25. // Note: If you receive compile errors (as I have in the Stino add-on for Sublime Text), set the compiler to 'Full Compilation'.
  26. //
  27.  
  28.  
  29. #include "FastLED.h"
  30.  
  31. #define LED_DT 13                                             // Data pin.
  32. #define NUM_LEDS 24                                           // Number of LED's.
  33. #define COLOR_ORDER GRB                                       // Change the order as necessary.
  34. #define LED_TYPE WS2811                                       // What kind of strip are you using?
  35. #define BRIGHTNESS  128                                       // How bright do we want to go.
  36.  
  37. CRGB leds[NUM_LEDS];
  38.  
  39. uint8_t thisdelay = 30;                                       // A delay value for the sequence(s).
  40.  
  41.  
  42. void setup() {
  43.   Serial.begin(9600);
  44.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  45.   FastLED.setBrightness(BRIGHTNESS);
  46.   set_max_power_in_volts_and_milliamps(5, 500);               // FastLED 2.1 Power management set at 5V, 500mA.
  47. }
  48.  
  49. void loop() {
  50.     cylon1();                                                                                                       // Bad display using FastLED.delay.
  51.     cylon1a();                                                                                                  // Good display using FastLED.delay and kludge.
  52.     cylon2();                                                                                                       // Good display using standard delay.
  53. } // loop()
  54.  
  55.  
  56.  
  57. void cylon1() {                                                                                             // Original technique, but with FastLED.delay
  58.     for(int i = 0; i < NUM_LEDS; i++) {
  59.         leds[i] = CRGB::Red;
  60.     show_at_max_brightness_for_power();
  61.         leds[i] = CRGB::Black;
  62.     FastLED.delay(thisdelay*2.5);                                                           // Doesn't look too good.
  63. //  delay_at_max_brightness_for_power(thisdelay*2.5);
  64. //  delay(thisdelay);
  65.     }
  66. } // cylon1()
  67.  
  68.  
  69. void cylon1a() {                                                                                            // Modified code with FastLED.delay.
  70.     for(int i = 0; i < NUM_LEDS; i++) {
  71.         if(i > 0) leds[i-1] = CRGB::Black;                                              // Kludgy workaround for FastLED.delay.
  72.         leds[i] = CRGB::Red;
  73.     show_at_max_brightness_for_power();
  74.     FastLED.delay(thisdelay*2.5);                                                           // Looks much better.
  75. //  delay_at_max_brightness_for_power(thisdelay*2.5);
  76. //  delay(thisdelay);
  77.     }
  78. } // cylon1a()
  79.  
  80.  
  81. void cylon2() {                                                                                             // Original code with standard delay
  82.     for(int i = NUM_LEDS-1; i >= 0; i--) {
  83.         leds[i] = CRGB::Red;
  84.     show_at_max_brightness_for_power();
  85.         leds[i] = CRGB::Black;
  86. //  FastLED.delay(thisdelay*2.5);
  87. //  delay_at_max_brightness_for_power(thisdelay*2.5);
  88.   delay(thisdelay);                                                                                     // Original delay works fine.
  89.     }
  90. } // cylon2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement