kitesurfer1404 / WS2812FX

WS2812 FX Library for Arduino and ESP8266
MIT License
1.58k stars 343 forks source link

Update modes.cpp #334

Closed BlockThor closed 1 year ago

BlockThor commented 1 year ago

Update 'mode_single_dynamic' and 'mode_multi_dynamic' to apply SIZE_OPTION. Harmonize speed.

BlockThor commented 1 year ago

Yes, you are right, it should be

fill(color_wheel(random8()), i, size);

We should slow down speed as a led sub-segments increased size. If we have normal speed 1/16 sec for 60 leds it normal, but in case SIZE_LARGE there are only 15 sub-segments and in this case it looks too fast, so it should be slow down accordingly by 4 time - multiply by size.

BlockThor commented 1 year ago

May I ask you? If I have more corrections or improvements, should I add it here, or better make new patch?

moose4lord commented 1 year ago

Unfortunately, there's still an issue with how the LED index is being calculated. If I run this test sketch with your PR:

#include <WS2812FX.h>

#define LED_PIN   22  // digital pin used to drive the LED strip
#define LED_COUNT 64  // number of LEDs on the strip

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);

  ws2812fx.init();
  ws2812fx.setBrightness(32);

  // parameters: index, start, stop, mode, color, speed, reverse
  ws2812fx.setSegment(0,  0, 31, FX_MODE_SINGLE_DYNAMIC, GREEN, 5000, SIZE_LARGE);
  ws2812fx.setSegment(1, 32, 63, FX_MODE_MULTI_DYNAMIC,  BLUE,  5000, SIZE_LARGE);

  ws2812fx.start();
}

void loop() {
  ws2812fx.service();
}

I see the last 4 LEDs in the strip are off. The line for(uint16_t i=_seg->start; i <= _seg->stop-size; i+=size) { does not calculate the LED index properly for the last iteration of the for loop. Can you double check?

BlockThor commented 1 year ago

Yes, you are right. It should be for(uint16_t i=_seg->start; i <= _seg->stop; i+=size) { But there is another problem: function fill did not check the limit for end of segment. And when I tested with two segments by 30 LEDs and SIZE_LARGE when i=28 + size = 32 first segment lit up leds from begining of second segment. Looks like the function fill should be overridden with another with an additional check for end of segment.

BlockThor commented 1 year ago

It would be better to start over and tackle each task individually.