Advertisement
Guest User

Untitled

a guest
Aug 27th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* * * * * * * * * * * * * * * * * * * *
  2. Updated script from https://www.reddit.com/r/FastLED/comments/1f253qz/
  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  64                // Board spec cautions against setting over 50 ~ like previous script, max is 64
  19. #define DITHER      BINARY_DITHER     // BINARY_DITHER | DISABLE_DITHER ~ Note: here "dither" means "temporal dither"
  20. #define CORRECTION  UncorrectedColor  // Color correction - not sure what other option makes more sense | TypicalSMD5050
  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.   setCpuFrequencyMhz(240);
  33.   // delay(3000); // This isn't needed for this board(?)
  34.   FastLED.addLeds
  35.     <LED_TYPE, DATA_PIN, RGB>
  36.     (leds, NUM_LEDS)
  37.     .setCorrection(CORRECTION)
  38.     .setDither(DITHER);
  39.   FastLED.setBrightness(BRIGHTNESS);
  40. }
  41.  
  42. void loop() {
  43.   EVERY_N_SECONDS(ANIMATE_FOR) swapAnimation();
  44.  
  45.   color_test ? cycleColor() : cycleBrightness(); // Call animation
  46.  
  47.   FastLED.show();
  48.   FastLED.delay(PAUSE);
  49.   delta += STEP;
  50. }
  51.  
  52. void swapAnimation() {
  53.   color_test = !color_test; // Swap animations
  54.   delta = 0; // Reset to start of whatever animation
  55.   if (color_test) FastLED.setBrightness(BRIGHTNESS); // Reset to preset BRIGHTNESS if testing colors
  56.   else for (int i = 0; i < NUM_LEDS; i++) leds[i] = CHSV(0,0,i * 4 + 1); // Only need to write to leds once if testing brightness
  57. }
  58.  
  59. void cycleColor() { // Cycle through color spectrum
  60.   for (int i = 0; i < NUM_LEDS; i++) leds[i] = CHSV(delta,255,i * 4 + 1);
  61. }
  62.  
  63. void cycleBrightness() { // Cycle through _valid_ brightnesses
  64.   if (delta >= BRIGHTNESS) delta = 0;
  65.   FastLED.setBrightness(BRIGHTNESS - delta);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement