Advertisement
atuline

chsvtest for FastLED

Aug 3rd, 2015
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1.  
  2. /* chsvtest by Andrew Tuline
  3.  
  4. This test is to show that when setting CHSV brightness to less than 16, the LED's remain dark if:
  5.  
  6. - FastLED.show() is performed only in setup.
  7. - FastLED.show() is performed within EVERY_N_MILLISECONDS loop at ~20 ms.
  8.  
  9. It works as expected if:
  10.  
  11. - FastLED.show() performed directly inside loop().
  12.  
  13.  
  14. Environment is:
  15.  
  16. - FastLED 3.1 from July 16, 2015
  17. - Windows 8.1
  18. - Arduino 1.6.3
  19. - Arduino Nano
  20. - 12 LED's of APA102 or WS2812 powered by the Nano both exhibit the same effect.
  21. - Nano powered by USB
  22.  
  23. */
  24.  
  25.  
  26. #include "FastLED.h"                                          // FastLED library.
  27.  
  28. #if FASTLED_VERSION < 3001000
  29. #error "Requires FastLED 3.1 or later; check github for latest code."
  30. #endif
  31.  
  32. // Fixed definitions cannot change on the fly.
  33. #define LED_DT 12                                             // Data pin to connect to the strip.
  34. #define LED_CK 11
  35. #define COLOR_ORDER GRB                                       // It's GRB for WS2812B and BGR for APA102.
  36. #define LED_TYPE WS2812                                       // What kind of strip are you using (WS2801, WS2812B or APA102)?
  37. #define NUM_LEDS 12                                           // Number of LED's.
  38.  
  39. // Initialize changeable global variables.
  40. uint8_t max_bright = 255;                                     // Overall brightness definition. It can be changed on the fly.
  41.  
  42. struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.
  43.  
  44. uint8_t bgbri = 15;                                           // Nothing shows up when 15, but turns on at 16. if showing LED's just in setup
  45.  
  46.  
  47. void setup() {
  48.   delay(3000);
  49.   Serial.begin(57600);
  50.  
  51.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);        // Use this for WS2812B
  52. //  LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS);  // Use this for WS2801 or APA102
  53.  
  54.   FastLED.setBrightness(max_bright);
  55.   for (int i = 0; i < NUM_LEDS; i++) {leds[i] = CHSV(0, 255, bgbri); Serial.print(leds[0].r); Serial.print(":"); Serial.print(leds[0].g); Serial.print(":"); Serial.println(leds[0].b); }
  56.  
  57. } // setup()
  58.  
  59.  
  60. void loop () {
  61.   EVERY_N_MILLISECONDS(20) {                                  // FastLED based non-blocking delay to update/display the sequence.
  62.     FastLED.show();
  63.   }
  64. //  FastLED.show();                                             // Uncomment this line and the LED's will display while bgbri < 15.
  65. } // loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement