@@ -39,6 +39,13 @@ const unsigned long
3939const uint16_t
4040 SerialTimeout = 60 ; // time before LEDs are shut off if no data (in seconds), 0 to disable
4141
42+ // --- Group Settings (uncomment to add)
43+ // Grouping will set a group of LEDs to the data received for a single one. This
44+ // lets you send less data to the device, increasing throughput and therefore
45+ // framerate - at the cost of resolution. Grouping only works if your strip is
46+ // evenly divisible by the amount of data sent.
47+ // #define GROUPING // enable the automatic grouping feature
48+
4249// --- Optional Settings (uncomment to add)
4350#define SERIAL_FLUSH // Serial buffer cleared on LED latch
4451// #define CLEAR_ON_START // LEDs are cleared on reset
@@ -89,6 +96,7 @@ const unsigned long Timebase = 1000; // time units per second
8996
9097void headerMode (uint8_t c);
9198void dataMode (uint8_t c);
99+ void groupProcessing ();
92100void timeouts ();
93101
94102// Macros initialized
@@ -226,6 +234,10 @@ void dataMode(uint8_t c){
226234
227235 // if all data has been read, write the output
228236 if (ledsRemaining == 0 ) {
237+ #if defined(GROUPING)
238+ groupProcessing ();
239+ #endif
240+
229241 FastLED.show ();
230242 channelIndex = 0 ; // reset channel tracking
231243 mode = Header; // begin next header search
@@ -236,6 +248,27 @@ void dataMode(uint8_t c){
236248 }
237249}
238250
251+ void groupProcessing () {
252+ // if we've received the same amount of data as there
253+ // are LEDs in the strip, don't do any group processing
254+ if (Num_Leds == ledIndex) return ;
255+
256+ const uint16_t GroupSize = Num_Leds / ledIndex;
257+ const uint16_t GroupRemainder = Num_Leds - (ledIndex * GroupSize);
258+
259+ // if the value isn't evenly divisible, don't bother trying to group
260+ // (it won't look right without significant processing, i.e. overhead)
261+ if (GroupRemainder != 0 ) return ;
262+
263+ // otherwise, iterate backwards through the array, copying each LED color
264+ // forwards to the rest of its group
265+ for (uint16_t group = 1 ; group <= ledIndex; ++group) {
266+ const CRGB GroupColor = leds[ledIndex - group];
267+ const uint16_t GroupStart = Num_Leds - (group * GroupSize);
268+ fill_solid (&leds[GroupStart], GroupSize, GroupColor);
269+ }
270+ }
271+
239272void timeouts (){
240273 const unsigned long t = now ();
241274
0 commit comments