From aefa737675ab27df0fb767433fd84513ba6faa54 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 8 Jan 2022 17:28:43 -0600 Subject: [PATCH] Completed "optimization" Pixels now lets you reserve memory for pixels so that the call to start the RF transmission can be done for multiple pixels at once. However, gain is not as much as expected. May need to revisit if driving a large matrix of pixels is needed. --- src/extras/Pixel.cpp | 30 +++++++++++++++--------------- src/extras/extras.ino | 28 +++++++++++++--------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/extras/Pixel.cpp b/src/extras/Pixel.cpp index 4c40f24..ad990c5 100644 --- a/src/extras/Pixel.cpp +++ b/src/extras/Pixel.cpp @@ -30,7 +30,7 @@ void Pixel::setRGB(uint8_t r, uint8_t g, uint8_t b, int nPixels){ if(!*rf) return; - uint32_t *pulses = (uint32_t *) malloc(96); + uint32_t *pulses = (uint32_t *) malloc(24*sizeof(uint32_t)); loadColor(getColorRGB(r,g,b),pulses); rf->start(pulses,24,nPixels); // start pulse train and repeat for nPixels @@ -44,25 +44,25 @@ void Pixel::setRGB(uint8_t r, uint8_t g, uint8_t b, int nPixels){ void Pixel::setColors(color_t *color, int nPixels){ if(!*rf) + return; + + uint32_t *pulses = (uint32_t *) malloc(nTrain*24*sizeof(uint32_t)); + + if(!pulses){ + Serial.printf("*** ERROR: Not enough memory to reserve for %d Pixels per batch transmission\n",nTrain); return; - - uint32_t x0,x1,x2; - - x0=micros(); - - uint32_t *pulses = (uint32_t *) malloc(nTrain*96); - - for(int i=0;istart(pulses,24); // start pulse train } - x1=micros(); - Serial.printf("%d\n",x1-x0); + int i,j; + + for(i=0;istart(pulses,j*24); + } - while(1); - delayMicroseconds(resetTime); free(pulses); + delayMicroseconds(resetTime); } /////////////////// diff --git a/src/extras/extras.ino b/src/extras/extras.ino index 5045f1b..5343ba5 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -73,7 +73,7 @@ struct Effect2 { } }; -Pixel px(21); +Pixel px(21,8); Effect1 effect1(&px,5); Effect2 effect2(&px,100); @@ -87,21 +87,19 @@ void setup() { Serial.printf("PX on Pin=%d check: %s\n",px.getPin(),px?"OKAY":"BAD"); px.setRGB(0,0,0,8); - px.setRGB(255,0,0,1); - delay(500); - px.setRGB(0,255,0,2); - delay(500); - px.setRGB(0,255,0,4); - delay(500); - px.setRGB(0,255,255,6); - delay(500); - px.setRGB(0,0,255,8); - delay(500); + for(int i=1;i<5;i++){ + px.setHSV(0,100,20,i); + delay(500); + } + + for(int i=5;i<8;i++){ + px.setHSV(60,100,30,i); + delay(500); + } -// while(1); - - - + px.setHSV(120,100,100,8); + delay(500); + } // end of setup() void loop(){