From 7c2d527dd8d92efe03d71b5743f46f230b309758 Mon Sep 17 00:00:00 2001 From: mrfaptastic <12006953+mrfaptastic@users.noreply.github.com> Date: Sun, 2 Apr 2023 13:12:53 +0100 Subject: Cleanup --- examples/3_DoubleBuffer/3_DoubleBuffer.ino | 90 ++++++++++++++++ examples/3_FM6126Panel/3_FM6126Panel.ino | 102 ------------------ examples/3_FM6126Panel/FM6126A.md | 51 --------- examples/3_FM6126Panel/README.md | 3 - .../4_HueValueSpectrumDemo.ino | 75 -------------- .../4_OtherShiftDriverPanel.ino | 114 +++++++++++++++++++++ examples/4_OtherShiftDriverPanel/FM6126A.md | 51 +++++++++ examples/4_OtherShiftDriverPanel/README.md | 3 + examples/BouncingSquares/BouncingSquares.ino | 84 --------------- 9 files changed, 258 insertions(+), 315 deletions(-) create mode 100644 examples/3_DoubleBuffer/3_DoubleBuffer.ino delete mode 100644 examples/3_FM6126Panel/3_FM6126Panel.ino delete mode 100644 examples/3_FM6126Panel/FM6126A.md delete mode 100644 examples/3_FM6126Panel/README.md delete mode 100644 examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino create mode 100644 examples/4_OtherShiftDriverPanel/4_OtherShiftDriverPanel.ino create mode 100644 examples/4_OtherShiftDriverPanel/FM6126A.md create mode 100644 examples/4_OtherShiftDriverPanel/README.md delete mode 100644 examples/BouncingSquares/BouncingSquares.ino (limited to 'examples') diff --git a/examples/3_DoubleBuffer/3_DoubleBuffer.ino b/examples/3_DoubleBuffer/3_DoubleBuffer.ino new file mode 100644 index 0000000..5a41d67 --- /dev/null +++ b/examples/3_DoubleBuffer/3_DoubleBuffer.ino @@ -0,0 +1,90 @@ +// Example uses the following configuration: mxconfig.double_buff = true; +// to enable double buffering, which means display->flipDMABuffer(); is required. + +// Bounce squares around the screen, doing the re-drawing in the background back-buffer. +// Double buffering is not always required in reality. + +#include + +MatrixPanel_I2S_DMA *display = nullptr; + +uint16_t myDARK = display->color565(64, 64, 64); +uint16_t myWHITE = display->color565(192, 192, 192); +uint16_t myRED = display->color565(255, 0, 0); +uint16_t myGREEN = display->color565(0, 255, 0); +uint16_t myBLUE = display->color565(0, 0, 255); + +uint16_t colours[5] = { myDARK, myWHITE, myRED, myGREEN, myBLUE }; + +struct Square +{ + float xpos, ypos; + float velocityx; + float velocityy; + boolean xdir, ydir; + uint16_t square_size; + uint16_t colour; +}; + +const int numSquares = 25; +Square Squares[numSquares]; + +void setup() +{ + // put your setup code here, to run once: + delay(1000); + Serial.begin(115200); + delay(200); + + Serial.println("...Starting Display"); + HUB75_I2S_CFG mxconfig; + mxconfig.double_buff = true; // <------------- Turn on double buffer + //mxconfig.clkphase = false; + + // OK, now we can create our matrix object + display = new MatrixPanel_I2S_DMA(mxconfig); + display->begin(); // setup display with pins as pre-defined in the library + + // Create some random squares + for (int i = 0; i < numSquares; i++) + { + Squares[i].square_size = random(2,10); + Squares[i].xpos = random(0, display->width() - Squares[i].square_size); + Squares[i].ypos = random(0, display->height() - Squares[i].square_size); + Squares[i].velocityx = static_cast (rand()) / static_cast (RAND_MAX); + Squares[i].velocityy = static_cast (rand()) / static_cast (RAND_MAX); + + int random_num = random(6); + Squares[i].colour = colours[random_num]; + } +} + +void loop() +{ + + display->flipDMABuffer(); // Show the back buffer, set currently output buffer to the back (i.e. no longer being sent to LED panels) + display->clearScreen(); // Now clear the back-buffer + + delay(16); // <----------- Shouldn't see this clearscreen occur as it happens on the back buffer when double buffering is enabled. + + for (int i = 0; i < numSquares; i++) + { + // Draw rect and then calculate + display->fillRect(Squares[i].xpos, Squares[i].ypos, Squares[i].square_size, Squares[i].square_size, Squares[i].colour); + + if (Squares[i].square_size + Squares[i].xpos >= display->width()) { + Squares[i].velocityx *= -1; + } else if (Squares[i].xpos <= 0) { + Squares[i].velocityx = abs (Squares[i].velocityx); + } + + if (Squares[i].square_size + Squares[i].ypos >= display->height()) { + Squares[i].velocityy *= -1; + } else if (Squares[i].ypos <= 0) { + Squares[i].velocityy = abs (Squares[i].velocityy); + } + + Squares[i].xpos += Squares[i].velocityx; + Squares[i].ypos += Squares[i].velocityy; + } +} diff --git a/examples/3_FM6126Panel/3_FM6126Panel.ino b/examples/3_FM6126Panel/3_FM6126Panel.ino deleted file mode 100644 index 3b706e1..0000000 --- a/examples/3_FM6126Panel/3_FM6126Panel.ino +++ /dev/null @@ -1,102 +0,0 @@ -// How to use this library with a FM6126 panel, thanks goes to: -// https://github.com/hzeller/rpi-rgb-led-matrix/issues/746 - -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// FM6126 support is still experimental - -// Output resolution and panel chain length configuration -#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. -#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 - - -// placeholder for the matrix object -MatrixPanel_I2S_DMA *dma_display = nullptr; - -/////////////////////////////////////////////////////////////// - -// FastLED variables for pattern output -uint16_t time_counter = 0, cycles = 0, fps = 0; -unsigned long fps_timer; - -CRGB currentColor; -CRGBPalette16 palettes[] = {HeatColors_p, LavaColors_p, RainbowColors_p, RainbowStripeColors_p, CloudColors_p}; -CRGBPalette16 currentPalette = palettes[0]; - - -CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) { - return ColorFromPalette(currentPalette, index, brightness, blendType); -} - -void setup(){ - - /* - The configuration for MatrixPanel_I2S_DMA object is held in HUB75_I2S_CFG structure, - All options has it's predefined default values. So we can create a new structure and redefine only the options we need - - Please refer to the '2_PatternPlasma.ino' example for detailed example of how to use the MatrixPanel_I2S_DMA configuration - if you need to change the pin mappings etc. - */ - - HUB75_I2S_CFG mxconfig( - PANEL_RES_X, // module width - PANEL_RES_Y, // module height - PANEL_CHAIN // Chain length - ); - - mxconfig.driver = HUB75_I2S_CFG::FM6126A; // in case that we use panels based on FM6126A chip, we can set it here before creating MatrixPanel_I2S_DMA object - - // OK, now we can create our matrix object - dma_display = new MatrixPanel_I2S_DMA(mxconfig); - - // If you experience ghosting, you will need to reduce the brightness level, not all RGB Matrix - // Panels are the same - some seem to display ghosting artefacts at lower brightness levels. - // In the setup() function do something like: - - // let's adjust default brightness to about 75% - dma_display->setBrightness8(192); // range is 0-255, 0 - 0%, 255 - 100% - - // Allocate memory and start DMA display - if( not dma_display->begin() ) - Serial.println("****** !KABOOM! Insufficient memory - allocation failed ***********"); - - fps_timer = millis(); - -} - -void loop(){ - for (int x = 0; x < dma_display->width(); x++) { - for (int y = 0; y < dma_display->height(); y++) { - int16_t v = 0; - uint8_t wibble = sin8(time_counter); - v += sin16(x * wibble * 3 + time_counter); - v += cos16(y * (128 - wibble) + time_counter); - v += sin16(y * x * cos8(-time_counter) / 8); - - currentColor = ColorFromPalette(currentPalette, (v >> 8) + 127); //, brightness, currentBlendType); - dma_display->drawPixelRGB888(x, y, currentColor.r, currentColor.g, currentColor.b); - } - } - - ++time_counter; - ++cycles; - ++fps; - - if (cycles >= 1024) { - time_counter = 0; - cycles = 0; - currentPalette = palettes[random(0,sizeof(palettes)/sizeof(palettes[0]))]; - } - - // print FPS rate every 5 seconds - // Note: this is NOT a matrix refresh rate, it's the number of data frames being drawn to the DMA buffer per second - if (fps_timer + 5000 < millis()){ - Serial.printf_P(PSTR("Effect fps: %d\n"), fps/5); - fps_timer = millis(); - fps = 0; - } -} \ No newline at end of file diff --git a/examples/3_FM6126Panel/FM6126A.md b/examples/3_FM6126Panel/FM6126A.md deleted file mode 100644 index 1641c16..0000000 --- a/examples/3_FM6126Panel/FM6126A.md +++ /dev/null @@ -1,51 +0,0 @@ -## The mystery of control registers for FM6126A chips - - -The only available Datasheet for this chips is in Chinese and does not shed a light on what those two control regs are. - -An excellent insight could be found here https://github.com/hzeller/rpi-rgb-led-matrix/issues/746#issuecomment-453860510 - - - -So there are two regs in this chip - **REG1** and **REG2**, -one could be written with 12 clock pulses (and usually called reg12, dunno why :)) -the other one could be written with 13 clock pulses (and usually called reg13, dunno why :)) - - -I've done some measurements on power consumption while toggling bits of **REG1** and it looks that it could provide a fine grained brightness control over the entire matrix with no need for bitbanging over RGB or EO pins. -There are 6 bits (6 to 11) giving an increased brightness (compared to all-zeroes) and 4 bits (2-5) giving decreased brightness!!! -Still unclear if FM6112A brightness control is internally PWMed or current limited, might require some poking with oscilloscope. - -So it seems that the most bright (and hungry for power) value is bool REG1[16] = {0,0,0,0,0, 1,1,1,1,1,1, 0,0,0,0,0}; and not {0,1,1,1,1, 1,1,1,1,1,1, 1,1,1,1,1} as it is usually used. -I'm not sure about bit 1 - it is either not used or I was unable to measure it's influence to brightness/power. - -Giving at least 10 bits of hardware brightness control opens pretty nice options for offloading and simplifying matrix output. Should dig into this more deeper. - -Here are some of the measurements I've took for 2 64x64 panels filled with white color - reg value and corresponding current drain in amps. - - -|REG1 |bit value|Current, amps | -|--|--|--| -|REG1| 0111111 00000| >5 amps| -|REG1| 0100010 00000| 3.890 amp| -|REG1| 0100000 00000| 3.885 amp| -|REG1| 0011110 00000| 3.640 amp| -|REG1| 0011100 00000| 3.620 amp| -|REG1| 0011000 00000| 3.240 amp| -|REG1| 0010010 00000| 2.520 amp| -|REG1| 0010001 00000| 2.518 amp| -|REG1| 0010001 10000| 2.493 amp| -|REG1| 0010000 00000| 2.490 amp| -|REG1| 0010000 11110| 2.214 amp| -|REG1| 0001100 00000| 2.120 amp| -|REG1| 0001000 00000| 1.750 amp| -|REG1| 0000100 00000| 1.375 amp| -|REG1| 0000010 00000| 1.000 amp| -|REG1| **0000000 00000**| 0.995 amp| -|REG1| 0000001 11111| 0.700 amp| -|REG1| 0000000 01111| 0.690 amp| -|REG1| 0000000 10000| 0.690 amp| -|REG1| 0000000 11110| 0.686 amp| - - -/Vortigont/ \ No newline at end of file diff --git a/examples/3_FM6126Panel/README.md b/examples/3_FM6126Panel/README.md deleted file mode 100644 index 65019e6..0000000 --- a/examples/3_FM6126Panel/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## FM6126 based LED Matrix Panel Reset ## - -FM6216 panels require a special reset sequence before they can be used, check your panel chipset if you have issues. Refer to this example. diff --git a/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino b/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino deleted file mode 100644 index e64d419..0000000 --- a/examples/4_HueValueSpectrumDemo/4_HueValueSpectrumDemo.ino +++ /dev/null @@ -1,75 +0,0 @@ -#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. -#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 - -#include - -MatrixPanel_I2S_DMA *dma_display = nullptr; - -void setup() { - 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 - PANEL_CHAIN, // chain length - _pins // pin mapping - ); - //mxconfig.clkphase = false; - //mxconfig.driver = HUB75_I2S_CFG::FM6126A; - - // Display Setup - dma_display = new MatrixPanel_I2S_DMA(mxconfig); - dma_display->begin(); - dma_display->clearScreen(); -} - -void loop() { - // Canvas loop - float t = (float)(millis()%4000)/4000.f; - 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){ - // top-middle part of screen, transition of value - float t = (2.f*y+1)/PANEL_RES_Y; - dma_display->drawPixelRGB888(x,y, - (r*t)*f, - (g*t)*f, - (b*t)*f - ); - }else{ - // 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)*f, - (g*t+1-t)*f, - (b*t+1-t)*f - ); - } - } - } -} diff --git a/examples/4_OtherShiftDriverPanel/4_OtherShiftDriverPanel.ino b/examples/4_OtherShiftDriverPanel/4_OtherShiftDriverPanel.ino new file mode 100644 index 0000000..e62cecc --- /dev/null +++ b/examples/4_OtherShiftDriverPanel/4_OtherShiftDriverPanel.ino @@ -0,0 +1,114 @@ +/********************************************************************** + * The library by default supports simple 'shift register' based panels + * with A,B,C,D,E lines to select a specific row, but there are plenty + * of examples of new chips coming on the market that work different. + * + * Please search through the project's issues. For some of these chips + * (you will need to look at the back of your panel to identify), this + * library has workarounds. This can be configured through using one of: + + // mxconfig.driver = HUB75_I2S_CFG::FM6126A; + //mxconfig.driver = HUB75_I2S_CFG::ICN2038S; + //mxconfig.driver = HUB75_I2S_CFG::FM6124; + //mxconfig.driver = HUB75_I2S_CFG::MBI5124; + */ + + +#include +#include +#include + +//////////////////////////////////////////////////////////////////// + +// Output resolution and panel chain length configuration +#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. +#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 + +// placeholder for the matrix object +MatrixPanel_I2S_DMA *dma_display = nullptr; + +/////////////////////////////////////////////////////////////// + +// FastLED variables for pattern output +uint16_t time_counter = 0, cycles = 0, fps = 0; +unsigned long fps_timer; + +CRGB currentColor; +CRGBPalette16 palettes[] = {HeatColors_p, LavaColors_p, RainbowColors_p, RainbowStripeColors_p, CloudColors_p}; +CRGBPalette16 currentPalette = palettes[0]; + + +CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) { + return ColorFromPalette(currentPalette, index, brightness, blendType); +} + +void setup(){ + + HUB75_I2S_CFG mxconfig( + PANEL_RES_X, // module width + PANEL_RES_Y, // module height + PANEL_CHAIN // Chain length + ); + + // in case that we use panels based on FM6126A chip, we can set it here before creating MatrixPanel_I2S_DMA object + mxconfig.driver = HUB75_I2S_CFG::FM6126A; + //mxconfig.driver = HUB75_I2S_CFG::ICN2038S; + //mxconfig.driver = HUB75_I2S_CFG::FM6124; + //mxconfig.driver = HUB75_I2S_CFG::MBI5124; + + + // OK, now we can create our matrix object + dma_display = new MatrixPanel_I2S_DMA(mxconfig); + + // If you experience ghosting, you will need to reduce the brightness level, not all RGB Matrix + // Panels are the same - some seem to display ghosting artefacts at lower brightness levels. + // In the setup() function do something like: + + // let's adjust default brightness to about 75% + dma_display->setBrightness8(192); // range is 0-255, 0 - 0%, 255 - 100% + + // Allocate memory and start DMA display + if( not dma_display->begin() ) + Serial.println("****** !KABOOM! Insufficient memory - allocation failed ***********"); + + fps_timer = millis(); + +} + +void loop(){ + for (int x = 0; x < dma_display->width(); x++) { + for (int y = 0; y < dma_display->height(); y++) { + int16_t v = 0; + uint8_t wibble = sin8(time_counter); + v += sin16(x * wibble * 3 + time_counter); + v += cos16(y * (128 - wibble) + time_counter); + v += sin16(y * x * cos8(-time_counter) / 8); + + currentColor = ColorFromPalette(currentPalette, (v >> 8) + 127); //, brightness, currentBlendType); + dma_display->drawPixelRGB888(x, y, currentColor.r, currentColor.g, currentColor.b); + } + } + + ++time_counter; + ++cycles; + ++fps; + + if (cycles >= 1024) { + time_counter = 0; + cycles = 0; + currentPalette = palettes[random(0,sizeof(palettes)/sizeof(palettes[0]))]; + } + + // print FPS rate every 5 seconds + // Note: this is NOT a matrix refresh rate, it's the number of data frames being drawn to the DMA buffer per second + if (fps_timer + 5000 < millis()){ + Serial.printf_P(PSTR("Effect fps: %d\n"), fps/5); + fps_timer = millis(); + fps = 0; + } +} + + +// FM6126 panel , thanks goes to: +// https://github.com/hzeller/rpi-rgb-led-matrix/issues/746 diff --git a/examples/4_OtherShiftDriverPanel/FM6126A.md b/examples/4_OtherShiftDriverPanel/FM6126A.md new file mode 100644 index 0000000..1641c16 --- /dev/null +++ b/examples/4_OtherShiftDriverPanel/FM6126A.md @@ -0,0 +1,51 @@ +## The mystery of control registers for FM6126A chips + + +The only available Datasheet for this chips is in Chinese and does not shed a light on what those two control regs are. + +An excellent insight could be found here https://github.com/hzeller/rpi-rgb-led-matrix/issues/746#issuecomment-453860510 + + + +So there are two regs in this chip - **REG1** and **REG2**, +one could be written with 12 clock pulses (and usually called reg12, dunno why :)) +the other one could be written with 13 clock pulses (and usually called reg13, dunno why :)) + + +I've done some measurements on power consumption while toggling bits of **REG1** and it looks that it could provide a fine grained brightness control over the entire matrix with no need for bitbanging over RGB or EO pins. +There are 6 bits (6 to 11) giving an increased brightness (compared to all-zeroes) and 4 bits (2-5) giving decreased brightness!!! +Still unclear if FM6112A brightness control is internally PWMed or current limited, might require some poking with oscilloscope. + +So it seems that the most bright (and hungry for power) value is bool REG1[16] = {0,0,0,0,0, 1,1,1,1,1,1, 0,0,0,0,0}; and not {0,1,1,1,1, 1,1,1,1,1,1, 1,1,1,1,1} as it is usually used. +I'm not sure about bit 1 - it is either not used or I was unable to measure it's influence to brightness/power. + +Giving at least 10 bits of hardware brightness control opens pretty nice options for offloading and simplifying matrix output. Should dig into this more deeper. + +Here are some of the measurements I've took for 2 64x64 panels filled with white color - reg value and corresponding current drain in amps. + + +|REG1 |bit value|Current, amps | +|--|--|--| +|REG1| 0111111 00000| >5 amps| +|REG1| 0100010 00000| 3.890 amp| +|REG1| 0100000 00000| 3.885 amp| +|REG1| 0011110 00000| 3.640 amp| +|REG1| 0011100 00000| 3.620 amp| +|REG1| 0011000 00000| 3.240 amp| +|REG1| 0010010 00000| 2.520 amp| +|REG1| 0010001 00000| 2.518 amp| +|REG1| 0010001 10000| 2.493 amp| +|REG1| 0010000 00000| 2.490 amp| +|REG1| 0010000 11110| 2.214 amp| +|REG1| 0001100 00000| 2.120 amp| +|REG1| 0001000 00000| 1.750 amp| +|REG1| 0000100 00000| 1.375 amp| +|REG1| 0000010 00000| 1.000 amp| +|REG1| **0000000 00000**| 0.995 amp| +|REG1| 0000001 11111| 0.700 amp| +|REG1| 0000000 01111| 0.690 amp| +|REG1| 0000000 10000| 0.690 amp| +|REG1| 0000000 11110| 0.686 amp| + + +/Vortigont/ \ No newline at end of file diff --git a/examples/4_OtherShiftDriverPanel/README.md b/examples/4_OtherShiftDriverPanel/README.md new file mode 100644 index 0000000..65019e6 --- /dev/null +++ b/examples/4_OtherShiftDriverPanel/README.md @@ -0,0 +1,3 @@ +## FM6126 based LED Matrix Panel Reset ## + +FM6216 panels require a special reset sequence before they can be used, check your panel chipset if you have issues. Refer to this example. diff --git a/examples/BouncingSquares/BouncingSquares.ino b/examples/BouncingSquares/BouncingSquares.ino deleted file mode 100644 index 6a01225..0000000 --- a/examples/BouncingSquares/BouncingSquares.ino +++ /dev/null @@ -1,84 +0,0 @@ -#include - -MatrixPanel_I2S_DMA *display = nullptr; - -uint16_t myDARK = display->color565(64, 64, 64); -uint16_t myWHITE = display->color565(192, 192, 192); -uint16_t myRED = display->color565(255, 0, 0); -uint16_t myGREEN = display->color565(0, 255, 0); -uint16_t myBLUE = display->color565(0, 0, 255); - -uint16_t colours[5] = { myDARK, myWHITE, myRED, myGREEN, myBLUE }; - -struct Square -{ - float xpos, ypos; - float velocityx; - float velocityy; - boolean xdir, ydir; - uint16_t square_size; - uint16_t colour; -}; - -const int numSquares = 25; -Square Squares[numSquares]; - -void setup() -{ - // put your setup code here, to run once: - delay(1000); - Serial.begin(115200); - delay(200); - - Serial.println("...Starting Display"); - HUB75_I2S_CFG mxconfig; - //mxconfig.double_buff = true; // Turn of double buffer - mxconfig.clkphase = false; - - // OK, now we can create our matrix object - display = new MatrixPanel_I2S_DMA(mxconfig); - display->begin(); // setup display with pins as pre-defined in the library - - // Create some Squares - for (int i = 0; i < numSquares; i++) - { - Squares[i].square_size = random(2,10); - Squares[i].xpos = random(0, display->width() - Squares[i].square_size); - Squares[i].ypos = random(0, display->height() - Squares[i].square_size); - Squares[i].velocityx = static_cast (rand()) / static_cast (RAND_MAX); - Squares[i].velocityy = static_cast (rand()) / static_cast (RAND_MAX); - //Squares[i].xdir = (random(2) == 1) ? true:false; - //Squares[i].ydir = (random(2) == 1) ? true:false; - - int random_num = random(6); - Squares[i].colour = colours[random_num]; - } -} - -void loop() -{ - display->flipDMABuffer(); // not used if double buffering isn't enabled - delay(25); - display->clearScreen(); - - for (int i = 0; i < numSquares; i++) - { - // Draw rect and then calculate - display->fillRect(Squares[i].xpos, Squares[i].ypos, Squares[i].square_size, Squares[i].square_size, Squares[i].colour); - - if (Squares[i].square_size + Squares[i].xpos >= display->width()) { - Squares[i].velocityx *= -1; - } else if (Squares[i].xpos <= 0) { - Squares[i].velocityx = abs (Squares[i].velocityx); - } - - if (Squares[i].square_size + Squares[i].ypos >= display->height()) { - Squares[i].velocityy *= -1; - } else if (Squares[i].ypos <= 0) { - Squares[i].velocityy = abs (Squares[i].velocityy); - } - - Squares[i].xpos += Squares[i].velocityx; - Squares[i].ypos += Squares[i].velocityy; - } -} -- cgit v1.3.1