Advertisement
Guest User

Teensy/FastLED gradient flicker

a guest
Aug 15th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | Source Code | 0 0
  1. #include <FastLED.h>
  2. #include "OctoWS2811.h"
  3.  
  4. #define NUM_LEDS_STRIP 248
  5. #define NUM_PINS 12
  6. #define NUM_LEDS_TABLE NUM_LEDS_STRIP*NUM_PINS // 2976
  7. #define LED_TYPE WS2812B
  8. #define COLOR_ORDER RGB
  9.  
  10. typedef struct fillgrad {
  11.     uint8_t one;
  12.     uint8_t two;
  13.     uint8_t three;
  14.     uint8_t four;
  15.     uint8_t five;
  16.     uint8_t six;
  17. } fillgrad_t;
  18.  
  19. fillgrad_t fg;
  20.  
  21. template <EOrder RGB_ORDER = RGB, uint8_t CHIP = WS2811_800kHz>
  22. class CTeensy4Controller : public CPixelLEDController<RGB_ORDER, 8, 0xFF>
  23. {
  24.     OctoWS2811 *pocto;
  25.  
  26. public:
  27.     CTeensy4Controller(OctoWS2811 *_pocto)
  28.         : pocto(_pocto){};
  29.  
  30.     virtual void init() {}
  31.     virtual void showPixels(PixelController<RGB_ORDER, 8, 0xFF> &pixels) {
  32.         uint32_t i = 0;
  33.         while (pixels.has(1)) {
  34.             uint8_t r = pixels.loadAndScale0();
  35.             uint8_t g = pixels.loadAndScale1();
  36.             uint8_t b = pixels.loadAndScale2();
  37.             pocto->setPixel(i++, r, g, b);
  38.             pixels.stepDithering();
  39.             pixels.advanceData();
  40.         }
  41.         pocto->show();
  42.     }
  43. };
  44.  
  45. byte pinList[NUM_PINS] = {0,8,9,1,2,10,  3,11,4,12,5,24};
  46. DMAMEM int displayMemory[NUM_LEDS_TABLE * 3];
  47. //DMAMEM int displayMemory[NUM_LEDS_TABLE * 3 / 4];     //also tried this
  48. int drawingMemory[NUM_LEDS_TABLE * 3];// * 3 / 4];
  49. //int drawingMemory[NUM_LEDS_TABLE * 3 / 4];                    //also tried this
  50. OctoWS2811 octo(NUM_LEDS_STRIP, displayMemory, drawingMemory,
  51.                 WS2811_RGB | WS2811_800kHz, NUM_PINS, pinList);
  52. CTeensy4Controller<RGB, WS2811_800kHz> *pcontroller;
  53. CRGB leds[NUM_LEDS_TABLE];
  54.  
  55. void setup() {
  56.     octo.begin();
  57.     pcontroller = new CTeensy4Controller<RGB, WS2811_800kHz>(&octo);
  58.  
  59.     FastLED.addLeds(pcontroller, leds, NUM_LEDS_TABLE);
  60.     fill_solid(leds, NUM_LEDS_TABLE, CRGB::Black);
  61.     FastLED.setBrightness(255);
  62. }
  63.  
  64. void loop() {
  65.     mode_fillgrad();
  66.     FastLED.show();
  67. }
  68.  
  69. void fillgrad_random() {
  70.     fg.one = random8(1,25);
  71.     fg.two = random8(0,10);
  72.     fg.three = random8(200,255);
  73.     fg.four = random8(1,25);
  74.     fg.five = random8(0,10);
  75.     fg.six = random8(200,255);
  76. }
  77.  
  78. void fill_grad() {
  79.     uint8_t starthue = beatsin8(fg.one, fg.two, fg.three);
  80.     uint8_t endhue = beatsin8(fg.four, fg.five, fg.six);
  81.  
  82.     if (starthue < endhue) {
  83.         fill_gradient(leds, NUM_LEDS_TABLE, CHSV(starthue,255,255), CHSV(endhue,255,255), FORWARD_HUES);
  84.     } else {
  85.         fill_gradient(leds, NUM_LEDS_TABLE, CHSV(starthue,255,255), CHSV(endhue,255,255), BACKWARD_HUES);
  86.     }
  87.  
  88.     EVERY_N_SECONDS(5) {
  89.         fillgrad_random();
  90.     }
  91. }
  92.  
  93. void mode_fillgrad() {
  94.     EVERY_N_MILLIS(10) {
  95.         fill_grad();
  96.     }
  97. }
  98.  
Tags: Arduino
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement