diff options
| author | Kouzerumatsu / Bananafox <46141631+Kouzeru@users.noreply.github.com> | 2023-02-08 22:33:14 +0800 |
|---|---|---|
| committer | Kouzerumatsu / Bananafox <46141631+Kouzeru@users.noreply.github.com> | 2023-02-08 22:33:14 +0800 |
| commit | 79e1897aed951e37ee14665b2e13d9c172c8cfaf (patch) | |
| tree | 2aee395dac145c7120d4eb71cc23150c41c599cb /examples | |
| parent | 9d4d12a43bd135de343853f4e7d1b2f2d59ee727 (diff) | |
Deeper color depth
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino b/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino index 3fcbb31..e64d419 100644 --- a/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino +++ b/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino @@ -2,38 +2,33 @@ #define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module. #define PANEL_CHAIN 1 // Total number of panels chained one to another -#define NO_CIE1931 -#define PIXEL_COLOUR_DEPTH_BITS 8 #include <ESP32-HUB75-MatrixPanel-I2S-DMA.h> MatrixPanel_I2S_DMA *dma_display = nullptr; -#define R1_PIN 25 -#define G1_PIN 26 -#define B1_PIN 27 -#define R2_PIN 14 -#define G2_PIN 12 -#define B2_PIN 13 -#define A_PIN 23 -#define B_PIN 19 -#define C_PIN 5 -#define D_PIN 17 -#define E_PIN -1 // required for 1/32 scan panels, esp for 64x64 or 128x64 displays -#define LAT_PIN 4 -#define OE_PIN 15 -#define CLK_PIN 16 - -uint32_t lastMillis; - void setup() { - HUB75_I2S_CFG::i2s_pins _pins={R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, LAT_PIN, OE_PIN, CLK_PIN}; + HUB75_I2S_CFG::i2s_pins _pins={ + 25, //R1_PIN, + 26, //G1_PIN, + 27, //B1_PIN, + 14, //R2_PIN, + 12, //G2_PIN, + 13, //B2_PIN, + 23, //A_PIN, + 19, //B_PIN, + 5, //C_PIN, + 17, //D_PIN, + 18, //E_PIN, + 4, //LAT_PIN, + 15, //OE_PIN, + 16, //CLK_PIN + }; HUB75_I2S_CFG mxconfig( PANEL_RES_X, // Module width PANEL_RES_Y, // Module height - 1, // chain length + PANEL_CHAIN, // chain length _pins // pin mapping ); - //mxconfig.gpio.e = 18; //mxconfig.clkphase = false; //mxconfig.driver = HUB75_I2S_CFG::FM6126A; @@ -46,26 +41,35 @@ void setup() { void loop() { // Canvas loop float t = (float)(millis()%4000)/4000.f; - for(int x = 0; x < PANEL_RES_X; x++){ - float r =max(min(cosf(2.f*PI*(t+(float)x/PANEL_RES_X+0.f/3.f))+0.5f,1.f),0.f); - float g =max(min(cosf(2.f*PI*(t+(float)x/PANEL_RES_X+1.f/3.f))+0.5f,1.f),0.f); - float b =max(min(cosf(2.f*PI*(t+(float)x/PANEL_RES_X+2.f/3.f))+0.5f,1.f),0.f); - for(int y = 0; y < PANEL_RES_Y; y++) + float tt = (float)((millis()%16000)/16000.f; + + for(int x = 0; x < PANEL_RES_X*PANEL_CHAIN; x++){ + // calculate the overal shade + float f = ((sin(tt-(float)x/PANEL_RES_Y/32.)*2.f*PI)+1)/2)*255; + // calculate hue spectrum into rgb + float r = max(min(cosf(2.f*PI*(t+((float)x/PANEL_RES_Y+0.f)/3.f))+0.5f,1.f),0.f); + float g = max(min(cosf(2.f*PI*(t+((float)x/PANEL_RES_Y+1.f)/3.f))+0.5f,1.f),0.f); + float b = max(min(cosf(2.f*PI*(t+((float)x/PANEL_RES_Y+2.f)/3.f))+0.5f,1.f),0.f); + + // iterate pixels for every row + for(int y = 0; y < PANEL_RES_Y; y++){ if(y*2 < PANEL_RES_Y){ - float t = (2.f*y)/PANEL_RES_Y; + // top-middle part of screen, transition of value + float t = (2.f*y+1)/PANEL_RES_Y; dma_display->drawPixelRGB888(x,y, - (r*t)*255, - (g*t)*255, - (b*t)*255 + (r*t)*f, + (g*t)*f, + (b*t)*f ); }else{ - float t = (2.f*(PANEL_RES_Y-y))/PANEL_RES_Y; + // middle to bottom of screen, transition of saturation + float t = (2.f*(PANEL_RES_Y-y)-1)/PANEL_RES_Y; dma_display->drawPixelRGB888(x,y, - (r*t+1-t)*255, - (g*t+1-t)*255, - (b*t+1-t)*255 + (r*t+1-t)*f, + (g*t+1-t)*f, + (b*t+1-t)*f ); } - + } } } |
