Advertisement
Guest User

Untitled

a guest
Aug 26th, 2024
71
0
75 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* * * * * * * * * * * * * * * * * * * *
  2. Test script demonstrating FastLED’s limitations in equally addressing RGB:
  3. (1) for low-value HSV throughout the color spectrum, and
  4. (2) when representing white at increasingly low brightnesses.
  5.  
  6. The first animation sets LEDs to incrimental (color) HSV values (starting at 1), then cycles hue at consistant brightness.
  7. The second animation sets LEDs to incrimental (white) HSV values (starting at 1), then incrimetally dims brightness.
  8.  
  9. The default values provided values are spectificly for Waveshare's "ESP32-S3-Matrix", wich has an onboard 8x8 RGB matrix.
  10. * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. #include <FastLED.h>
  13.  
  14. #define NUM_LEDS    64              // 8x8 matrix, but this doesn't do anything 2D
  15. #define LED_TYPE    WS2811          // Just a guess, but it seems to work(?)
  16. #define PIN_ORDER   RGB             // If set to "ESP32S3 Dev Module", otherwise try "GRB"
  17. #define DATA_PIN    14              // Not SPI; no CLOCK_PIN
  18. #define BRIGHTNESS  255             // Board spec cautions against setting over 50 (as written, max is 64)
  19. #define DITHER      DISABLE_DITHER  // BINARY_DITHER | DISABLE_DITHER
  20. #define CORRECTION  TypicalSMD5050  // Color correction - not sure what other option makes more sense
  21.  
  22. #define ANIMATE_FOR 10              // Time in seconds to view each animation before switching
  23. #define STEP        1               // Incremental change of hue and brightness
  24. #define PAUSE       15              // Time to view each color/brigtness step in ms
  25.  
  26. CRGB leds[NUM_LEDS];
  27.  
  28. static uint8_t  delta      = 0;
  29. static bool     color_test = true;
  30.  
  31. void setup() {
  32.   // delay(3000); // This isn't needed for this board(?)
  33.   FastLED.addLeds
  34.     <LED_TYPE, DATA_PIN, RGB>
  35.     (leds, NUM_LEDS)
  36.     .setCorrection(CORRECTION)
  37.     .setDither(DISABLE_DITHER);
  38.   FastLED.setBrightness(BRIGHTNESS);
  39. }
  40.  
  41. void loop() {
  42.   EVERY_N_SECONDS(ANIMATE_FOR) swapAnimation();
  43.  
  44.   color_test ? cycleColor() : cycleBrightness(); // Call animation
  45.  
  46.   FastLED.show();
  47.   delay(PAUSE);
  48.   delta += STEP;
  49. }
  50.  
  51. void swapAnimation() {
  52.   color_test = !color_test; // Swap animations
  53.   delta = 0; // Reset to start of whatever animation
  54.   if (color_test) FastLED.setBrightness(BRIGHTNESS); // Reset to preset BRIGHTNESS if testing colors
  55.   else for (int i = 0; i < NUM_LEDS; i++) leds[i] = CHSV(0,0,i+1); // Only need to write to leds once if testing brightness
  56. }
  57.  
  58. void cycleColor() { // Cycle through color spectrum
  59.   for (int i = 0; i < NUM_LEDS; i++) leds[i] = CHSV(delta,255,i+1);
  60. }
  61.  
  62. void cycleBrightness() { // Cycle through _valid_ brightnesses
  63.   if (delta >= BRIGHTNESS) delta = 0;
  64.   FastLED.setBrightness(BRIGHTNESS - delta);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement