aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authormrfaptastic <12006953+mrfaptastic@users.noreply.github.com>2021-08-19 19:39:08 +0100
committermrfaptastic <12006953+mrfaptastic@users.noreply.github.com>2021-08-19 19:39:08 +0100
commit8dd6bf51b851ff3f32a7f981b76ed240118dbc24 (patch)
tree2ffbc9198a3902a251a8642f941e37b5eca0ef01 /examples
parent055ff08fe51da232c28d0fffeda6a4808eb141c1 (diff)
Update double buffer example
Diffstat (limited to 'examples')
-rw-r--r--examples/DoubleBufferSwap/DoubleBufferSwap.ino83
-rw-r--r--examples/SmoothDoubleBuffer/SmoothDoubleBuffer.ino65
2 files changed, 65 insertions, 83 deletions
diff --git a/examples/DoubleBufferSwap/DoubleBufferSwap.ino b/examples/DoubleBufferSwap/DoubleBufferSwap.ino
deleted file mode 100644
index 997da7b..0000000
--- a/examples/DoubleBufferSwap/DoubleBufferSwap.ino
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
-
-MatrixPanel_I2S_DMA *display = nullptr;
-
-const byte row0 = 2+0*10;
-const byte row1 = 2+1*10;
-const byte row2 = 2+2*10;
-
-
-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
-
- // OK, now we can create our matrix object
- display = new MatrixPanel_I2S_DMA(mxconfig);
-
-
- display->begin(); // setup display with pins as per defined in the library
- display->setTextColor(display->color565(255, 255, 255));
-
-
- // Buffer 0 test
- display->fillScreen(display->color565(128, 0, 0));
- display->setCursor(3, row0);
- display->print(F("Buffer 0"));
- display->setCursor(3, row1);
- display->print(F(" Buffer 0"));
- Serial.println("Wrote to to Buffer 0");
- display->showDMABuffer();
- delay(1500);
-
- // Buffer 1 test
- display->flipDMABuffer();
- display->fillScreen(display->color565(0, 128, 0)); // shouldn't see this
- display->setCursor(3, row0);
- display->print(F("Buffer 1"));
- display->setCursor(3, row2);
- display->print(F(" Buffer 1"));
-
- Serial.println("Wrote to to Buffer 1");
- display->showDMABuffer();
- delay(1500);
-
-}
-
-void loop() {
-
- // Flip the back buffer
- display->flipDMABuffer();
-
- // Write: Set bottow row to black
- for (int y=20;y<MATRIX_HEIGHT; y++)
- for (int x=0;x<MATRIX_WIDTH; x++)
- {
- display->drawPixelRGB888( x, y, 0, 0, 0);
- }
-
- // Write: Set bottom row to blue (this is what should show)
- for (int y=20;y<MATRIX_HEIGHT; y++)
- for (int x=0;x<MATRIX_WIDTH; x++)
- {
- display->drawPixelRGB888( x, y, 0, 0, 64);
- }
-
- // Now show this back buffer
- display->showDMABuffer();
- delay(1000);
-
- // Flip back buffer
- display->flipDMABuffer();
-
- // Show this buffer
- display->showDMABuffer();
- delay(1000);
-
-} \ No newline at end of file
diff --git a/examples/SmoothDoubleBuffer/SmoothDoubleBuffer.ino b/examples/SmoothDoubleBuffer/SmoothDoubleBuffer.ino
new file mode 100644
index 0000000..114f5ee
--- /dev/null
+++ b/examples/SmoothDoubleBuffer/SmoothDoubleBuffer.ino
@@ -0,0 +1,65 @@
+#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
+
+MatrixPanel_I2S_DMA *display = nullptr;
+
+const byte row0 = 2+0*11;
+const byte row1 = 2+1*11;
+const byte row2 = 2+2*11;
+
+int start_x = 0;
+int buffer_id = 0;
+
+
+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 = true;
+
+ // 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
+ display->setTextColor(display->color565(255, 255, 255));
+
+ start_x = display->width();
+}
+
+const int square_size = 16;
+void loop()
+{
+ display->flipDMABuffer();
+ //if ( !display->backbuffready() ) return;
+ //display->showDMABuffer();
+ display->clearScreen();
+
+ buffer_id ^= 1;
+
+ // Blue square on the left is printed to BOTH buffers.
+ display->fillRect(0, 0, square_size/2, square_size/2, display->color565(0,0,200));
+
+ start_x--;
+
+ if (buffer_id)
+ {
+ display->setCursor(3, row1);
+ display->fillRect(start_x, 6, square_size, square_size, display->color565(200,0,0));
+ //delay(40); // simulate slow drawing operation
+ }
+ else
+ {
+ display->setCursor(3, row2);
+ display->fillRect(10, start_x, square_size, square_size, display->color565(0,200,0));
+ }
+
+ display->printf("Buffer %d", buffer_id);
+
+ if (start_x < (-1*square_size)) start_x = display->width()+square_size;
+
+} \ No newline at end of file