Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cylon FastLED.delay issue with FastLED 2.1
- //
- // This is modified from the FastLED Cylon example
- //
- // By: Andrew Tuline
- //
- // Date: Sep, 2014
- //
- // This demonstrates LED duty cycle issues with FastLED.delay, and a kludgy workaround.
- //
- //
- // Some routines, such as the Cylon example work as follows:
- //
- // - Set an LED Colour
- // - FastLED.show
- // - Clear the LED Colour
- // - Delay
- //
- // The problem is that with the above technique, unlike a standard delay() statement, when using FastLED.delay,
- // the LED's don't show for the entire delay duration. As a result, the LED's have a significantly
- // lower duty cycle.
- //
- // FastLED 2.1 is available at https://github.com/FastLED/FastLED/tree/FastLED2.1
- //
- // Note: If you receive compile errors (as I have in the Stino add-on for Sublime Text), set the compiler to 'Full Compilation'.
- //
- #include "FastLED.h"
- #define LED_DT 13 // Data pin.
- #define NUM_LEDS 24 // Number of LED's.
- #define COLOR_ORDER GRB // Change the order as necessary.
- #define LED_TYPE WS2811 // What kind of strip are you using?
- #define BRIGHTNESS 128 // How bright do we want to go.
- CRGB leds[NUM_LEDS];
- uint8_t thisdelay = 30; // A delay value for the sequence(s).
- void setup() {
- Serial.begin(9600);
- LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- set_max_power_in_volts_and_milliamps(5, 500); // FastLED 2.1 Power management set at 5V, 500mA.
- }
- void loop() {
- cylon1(); // Bad display using FastLED.delay.
- cylon1a(); // Good display using FastLED.delay and kludge.
- cylon2(); // Good display using standard delay.
- } // loop()
- void cylon1() { // Original technique, but with FastLED.delay
- for(int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CRGB::Red;
- show_at_max_brightness_for_power();
- leds[i] = CRGB::Black;
- FastLED.delay(thisdelay*2.5); // Doesn't look too good.
- // delay_at_max_brightness_for_power(thisdelay*2.5);
- // delay(thisdelay);
- }
- } // cylon1()
- void cylon1a() { // Modified code with FastLED.delay.
- for(int i = 0; i < NUM_LEDS; i++) {
- if(i > 0) leds[i-1] = CRGB::Black; // Kludgy workaround for FastLED.delay.
- leds[i] = CRGB::Red;
- show_at_max_brightness_for_power();
- FastLED.delay(thisdelay*2.5); // Looks much better.
- // delay_at_max_brightness_for_power(thisdelay*2.5);
- // delay(thisdelay);
- }
- } // cylon1a()
- void cylon2() { // Original code with standard delay
- for(int i = NUM_LEDS-1; i >= 0; i--) {
- leds[i] = CRGB::Red;
- show_at_max_brightness_for_power();
- leds[i] = CRGB::Black;
- // FastLED.delay(thisdelay*2.5);
- // delay_at_max_brightness_for_power(thisdelay*2.5);
- delay(thisdelay); // Original delay works fine.
- }
- } // cylon2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement