diff --git a/examples/ESP32_I2S_DMA_Matrix/SetNumbers/AlphaTest/AlphaTest.ino b/examples/ESP32_I2S_DMA_Matrix/SetNumbers/AlphaTest/AlphaTest.ino new file mode 100644 index 0000000..1af97e8 --- /dev/null +++ b/examples/ESP32_I2S_DMA_Matrix/SetNumbers/AlphaTest/AlphaTest.ino @@ -0,0 +1,141 @@ +/******************************************************************* + Example showing writing text using the TetrisAnimation + library for the ESP32. + * * + Written by Brian Lough (witnessmenow on Github) + + *******************************************************************/ + +// ---------------------------- +// Standard Libraries - Already Installed if you have ESP32 set up +// ---------------------------- + +// ---------------------------- +// Additional Libraries - each one of these will need to be installed. +// ---------------------------- + +#include +// This is the library for interfacing with the display + +// Can be installed from the library manager (Search for "ESP32 64x32 LED MATRIX") +// https://github.com/mrfaptastic/ESP32-RGB64x32MatrixPanel-I2S-DMA + +// Adafruit GFX library is a dependancy for the matrix Library +// Can be installed from the library manager +// https://github.com/adafruit/Adafruit-GFX-Library + +#include +// This library! +// https://github.com/toblum/TetrisAnimation + + +unsigned long animationDue = 0; +unsigned long animationDelay = 100; // Smaller number == faster +bool finishedAnimating = false; + +RGB64x32MatrixPanel_I2S_DMA dma_display(true); //true enables the double buffer + +// Some standard colors +uint16_t myRED = dma_display.color565(255, 0, 0); +uint16_t myGREEN = dma_display.color565(0, 255, 0); +uint16_t myBLUE = dma_display.color565(0, 0, 255); +uint16_t myWHITE = dma_display.color565(255, 255, 255); +uint16_t myYELLOW = dma_display.color565(255, 255, 0); +uint16_t myCYAN = dma_display.color565(0, 255, 255); +uint16_t myMAGENTA = dma_display.color565(255, 0, 255); +uint16_t myBLACK = dma_display.color565(0, 0, 0); + +uint16_t myCOLORS[8] = {myRED, myGREEN, myBLUE, myWHITE, myYELLOW, myCYAN, myMAGENTA, myBLACK}; + +TetrisMatrixDraw tetris(dma_display); + +void animationHandler() +{ + // Not clearing the display and redrawing it when you + // dont need to + if (!finishedAnimating) { + dma_display.flipDMABuffer(); + dma_display.fillScreen(myBLACK); + finishedAnimating = tetris.drawText(5, 48, 32); + //finishedAnimating = tetris.drawNumbers(0, 48, false, 32); + dma_display.showDMABuffer(); + } + +} + +void drawIntro(int x = 0, int y = 0) +{ + tetris.drawChar("T", x, y, myCYAN); + tetris.drawChar("e", x + 5, y, myMAGENTA); + tetris.drawChar("t", x + 11, y, myYELLOW); + tetris.drawChar("r", x + 17, y, myGREEN); + tetris.drawChar("i", x + 22, y, myBLUE); + tetris.drawChar("s", x + 27, y, myRED); + + tetris.drawChar("T", x + 6, y + 9, myRED); + tetris.drawChar("i", x + 11, y + 9, myWHITE); + tetris.drawChar("m", x + 16, y + 9, myCYAN); + tetris.drawChar("e", x + 22, y + 9, myMAGENTA); +} + +void setup() { + Serial.begin(115200); + // Intialise display library + dma_display.begin(); + dma_display.fillScreen(myBLACK); + + dma_display.flipDMABuffer(); + dma_display.fillScreen(myBLACK); + drawIntro(10, 10); + dma_display.showDMABuffer(); + delay(2000); + + finishedAnimating = false; + tetris.setText("HELLO!"); + +} + +int counter = 0; + +void loop() { + unsigned long now = millis(); + if (now > animationDue) { + animationHandler(); + animationDue = now + animationDelay; + } + + if (finishedAnimating) { + delay(5000); + switch (counter) { + case 0: + tetris.setText("!#$%&'()"); + break; + case 1: + tetris.setText("*+,-./"); + break; + case 2: + tetris.setText("01234567"); + break; + case 3: + tetris.setText("89:;<=>?"); + break; + case 4: + tetris.setText("@ABCDEFG"); + break; + case 5: + tetris.setText("HIJKLMNO"); + break; + case 6: + tetris.setText("PQRSTUVW"); + break; + case 7: + tetris.setText("XYZ"); + break; + } + counter ++; + if(counter > 7){ + counter = 0; + } + finishedAnimating = false; + } +} diff --git a/src/TetrisLetters.h b/src/TetrisLetters.h index e201fee..ebb80d6 100644 --- a/src/TetrisLetters.h +++ b/src/TetrisLetters.h @@ -14,7 +14,7 @@ typedef struct int blocktype; // Number of the block type int color; // Color of the brick int x_pos; // x-position (starting from the left number staring point) where the brick should be placed - int y_stop; // y-position (1-16, where 16 is the last line of the matrix) where the brick should stop falling + int y_stop_offset; // how many blocks above the bottom should this block stop int num_rot; // Number of 90-degree (clockwise) rotations a brick is turned from the standard position } fall_instr_let; @@ -27,11 +27,11 @@ typedef struct // ********************************************************************* static const fall_instr_let a33[5] = { - {0,0,2,16,0}, - {2,5,3,13,2}, - {1,3,1,13,2}, - {7,1,1,10,3}, - {7,6,3,10,0} + {0,0,2,0,0}, + {2,5,3,3,2}, + {1,3,1,3,2}, + {7,1,1,6,3}, + {7,6,3,6,0} }; // ********************************************************************* @@ -39,10 +39,10 @@ static const fall_instr_let a33[5] = { // ********************************************************************* static const fall_instr_let a34[4] = { - {7,0,1,11,3}, - {7,1,4,11,3}, - {7,2,1,10,1}, - {7,5,4,10,1} + {7,0,1,5,3}, + {7,1,4,5,3}, + {7,2,1,6,1}, + {7,5,4,6,1} }; // ********************************************************************* @@ -50,15 +50,15 @@ static const fall_instr_let a34[4] = { // ********************************************************************* static const fall_instr_let a35[9] = { - {7,0,0,16,2}, - {7,5,4,16,1}, - {0,6,2,15,0}, - {7,3,0,14,2}, - {7,1,4,14,1}, - {6,3,0,12,2}, - {6,4,3,12,2}, - {6,6,0,10,0}, - {6,7,3,10,0} + {7,0,0,0,2}, + {7,5,4,0,1}, + {0,6,2,1,0}, + {7,3,0,2,2}, + {7,1,4,2,1}, + {6,3,0,4,2}, + {6,4,3,4,2}, + {6,6,0,6,0}, + {6,7,3,6,0} }; // ********************************************************************* @@ -66,14 +66,14 @@ static const fall_instr_let a35[9] = { // ********************************************************************* static const fall_instr_let a36[8] = { - {2,2,0,16,3}, - {7,0,3,16,1}, - {7,3,4,14,3}, - {1,6,2,13,3}, - {1,7,1,13,1}, - {7,3,0,12,1}, - {7,1,1,10,3}, - {2,2,3,10,1} + {2,2,0,0,3}, + {7,0,3,0,1}, + {7,3,4,2,3}, + {1,6,2,3,3}, + {1,7,1,3,1}, + {7,3,0,4,1}, + {7,1,1,6,3}, + {2,2,3,6,1} }; // ********************************************************************* @@ -81,13 +81,13 @@ static const fall_instr_let a36[8] = { // ********************************************************************* static const fall_instr_let a37[7] = { - {0,6,4,16,0}, - {7,1,0,16,3}, - {7,3,1,15,1}, - {0,0,2,13,0}, - {7,5,3,12,0}, - {7,7,4,10,1}, - {0,2,0,10,0} + {0,6,4,0,0}, + {7,1,0,0,3}, + {7,3,1,1,1}, + {0,0,2,3,0}, + {7,5,3,4,0}, + {7,7,4,6,1}, + {0,2,0,6,0} }; // ********************************************************************* @@ -95,14 +95,14 @@ static const fall_instr_let a37[7] = { // ********************************************************************* static const fall_instr_let a38[8] = { - {2,1,1,16,1}, - {4,0,4,16,0}, - {5,4,0,15,0}, - {6,7,2,14,3}, - {7,6,1,12,0}, - {5,3,4,12,0}, - {5,1,0,11,0}, - {2,2,2,10,3} + {2,1,1,0,1}, + {4,0,4,0,0}, + {5,4,0,1,0}, + {6,7,2,2,3}, + {7,6,1,4,0}, + {5,3,4,4,0}, + {5,1,0,5,0}, + {2,2,2,6,3} }; // ********************************************************************* @@ -110,8 +110,8 @@ static const fall_instr_let a38[8] = { // ********************************************************************* static const fall_instr_let a39[2] = { - {7,3,2,10,1}, - {7,0,2,11,3} + {7,0,2,5,3}, + {7,3,2,6,1}, }; // ********************************************************************* @@ -119,10 +119,10 @@ static const fall_instr_let a39[2] = { // ********************************************************************* static const fall_instr_let a40[4] = { - {5,0,1,16,1}, - {2,6,0,14,0}, - {2,3,0,13,2}, - {4,5,1,10,1} + {5,0,1,0,1}, + {2,6,0,2,0}, + {2,3,0,3,2}, + {4,5,1,6,1} }; // ********************************************************************* @@ -130,10 +130,10 @@ static const fall_instr_let a40[4] = { // ********************************************************************* static const fall_instr_let a41[4] = { - {4,6,2,16,1}, - {2,0,4,14,0}, - {2,3,4,13,2}, - {5,6,2,10,1} + {4,6,2,0,1}, + {2,0,4,2,0}, + {2,3,4,3,2}, + {5,6,2,6,1} }; // ********************************************************************* @@ -141,12 +141,12 @@ static const fall_instr_let a41[4] = { // ********************************************************************* static const fall_instr_let a42[6] = { - {4,6,0,14,1}, - {5,5,3,14,1}, - {0,2,1,12,0}, - {0,0,3,12,0}, - {2,1,3,10,1}, - {1,2,0,10,3} + {4,6,0,2,1}, + {5,5,3,2,1}, + {0,2,1,4,0}, + {0,0,3,4,0}, + {2,1,3,6,1}, + {1,2,0,6,3} }; // ********************************************************************* @@ -154,11 +154,11 @@ static const fall_instr_let a42[6] = { // ********************************************************************* static const fall_instr_let a43[5] = { - {2,1,2,15,0}, - {2,6,0,14,3}, - {0,3,4,13,0}, - {3,4,0,12,0}, - {0,2,2,11,0} + {2,1,2,1,0}, + {2,6,0,2,3}, + {0,3,4,3,0}, + {3,4,0,4,0}, + {0,2,2,5,0} }; // ********************************************************************* @@ -166,8 +166,8 @@ static const fall_instr_let a43[5] = { // ********************************************************************* static const fall_instr_let a44[2] = { - {7,4,1,16,3}, - {7,0,2,15,2} + {7,4,1,0,3}, + {7,0,2,1,2} }; // ********************************************************************* @@ -175,9 +175,9 @@ static const fall_instr_let a44[2] = { // ********************************************************************* static const fall_instr_let a45[3] = { - {3,1,1,13,0}, - {2,6,3,13,3}, - {1,0,0,13,1} + {3,1,1,3,0}, + {2,6,3,3,3}, + {1,0,0,3,1} }; @@ -186,7 +186,7 @@ static const fall_instr_let a45[3] = { // ********************************************************************* static const fall_instr_let a46[1] = { - {0,1,3,16,0} + {0,1,3,0,0} }; // ********************************************************************* @@ -194,11 +194,11 @@ static const fall_instr_let a46[1] = { // ********************************************************************* static const fall_instr_let a47[5] = { - {4,6,0,16,1}, - {7,0,1,14,3}, - {7,3,2,13,2}, - {7,5,3,11,0}, - {7,7,4,10,1} + {4,6,0,0,1}, + {7,0,1,2,3}, + {7,3,2,3,2}, + {7,5,3,5,0}, + {7,7,4,6,1} }; // ********************************************************************* @@ -206,16 +206,16 @@ static const fall_instr_let a47[5] = { // ********************************************************************* static const fall_instr_let a48[10] = { - {7,0,2,16,3}, - {6,3,0,16,2}, - {7,4,4,16,1}, - {3,2,0,14,1}, - {6,5,1,14,1}, - {0,1,4,14,0}, - {1,3,3,12,3}, - {6,7,0,11,3}, - {0,2,2,10,0}, - {6,3,4,11,1} + {7,0,2,0,3}, + {6,3,0,0,2}, + {7,4,4,0,1}, + {3,2,0,2,1}, + {6,5,1,2,1}, + {0,1,4,2,0}, + {1,3,3,4,3}, + {6,7,0,5,3}, + {0,2,2,6,0}, + {6,3,4,5,1} }; // ********************************************************************* @@ -223,14 +223,14 @@ static const fall_instr_let a48[10] = { // ********************************************************************* static const fall_instr_let a49[8] = { - {0,4,0,16,0}, - {1,2,2,16,1}, - {1,4,3,16,3}, - {7,3,2,14,3}, - {5,1,2,13,0}, - {6,6,0,11,0}, - {7,6,0,10,1}, - {0,0,2,10,0} + {0,4,0,0,0}, + {1,2,2,0,1}, + {1,4,3,0,3}, + {7,3,2,2,3}, + {5,1,2,3,0}, + {6,6,0,5,0}, + {7,6,0,6,1}, + {0,0,2,6,0} }; // ********************************************************************* @@ -238,15 +238,15 @@ static const fall_instr_let a49[8] = { // ********************************************************************* static const fall_instr_let a50[9] = { - {7,4,0,16,2}, - {1,2,2,16,1}, - {1,6,3,16,3}, - {0,2,0,14,0}, - {1,3,2,13,3}, - {1,2,4,13,2}, - {6,6,3,10,0}, - {7,0,2,10,1}, - {0,6,0,10,0} + {7,4,0,0,2}, + {1,2,2,0,1}, + {1,6,3,0,3}, + {0,2,0,2,0}, + {1,3,2,3,3}, + {1,2,4,3,2}, + {6,6,3,6,0}, + {7,0,2,6,1}, + {0,6,0,6,0} }; // ********************************************************************* @@ -254,15 +254,15 @@ static const fall_instr_let a50[9] = { // ********************************************************************* static const fall_instr_let a51[9] = { - {1,2,1,16,3}, - {1,5,0,16,1}, - {5,4,4,16,0}, - {6,6,3,14,2}, - {0,2,1,13,0}, - {1,1,3,12,3}, - {6,5,4,11,1}, - {1,3,1,10,3}, - {1,3,0,10,1} + {1,2,1,0,3}, + {1,5,0,0,1}, + {5,4,4,0,0}, + {6,6,3,2,2}, + {0,2,1,3,0}, + {1,1,3,4,3}, + {6,5,4,5,1}, + {1,3,1,6,3}, + {1,3,0,6,1} }; // ********************************************************************* @@ -270,14 +270,14 @@ static const fall_instr_let a51[9] = { // ********************************************************************* static const fall_instr_let a52[8] = { - {2,1,4,16,0}, - {3,2,4,15,1}, - {3,3,5,13,3}, - {1,0,1,13,3}, - {1,5,0,13,1}, - {7,1,0,11,3}, - {7,3,0,10,1}, - {2,6,4,11,2} + {2,1,4,0,0}, + {3,2,4,1,1}, + {3,3,5,3,3}, + {1,0,1,3,3}, + {1,5,0,3,1}, + {7,1,0,5,3}, + {7,3,0,6,1}, + {2,6,4,5,2} }; // ********************************************************************* @@ -285,16 +285,16 @@ static const fall_instr_let a52[8] = { // ********************************************************************* static const fall_instr_let a53[10] = { - {2,3,0,16,1}, - {2,4,1,16,3}, - {0,6,4,16,0}, - {0,7,4,14,0}, - {2,1,1,13,1}, - {2,5,0,13,2}, - {3,2,2,12,0}, - {1,4,0,10,1}, - {1,1,1,10,3}, - {0,0,4,10,0} + {2,3,0,0,1}, + {2,4,1,0,3}, + {0,6,4,0,0}, + {0,7,4,2,0}, + {2,1,1,3,1}, + {2,5,0,3,2}, + {3,2,2,4,0}, + {1,4,0,6,1}, + {1,1,1,6,3}, + {0,0,4,6,0} }; // ********************************************************************* @@ -302,16 +302,16 @@ static const fall_instr_let a53[10] = { // ********************************************************************* static const fall_instr_let a54[10] = { - {4,4,1,16,1}, - {4,3,3,16,1}, - {2,3,0,15,0}, - {0,0,4,14,0}, - {3,3,0,14,1}, - {7,4,1,13,2}, - {7,2,3,13,1}, - {6,6,0,11,3}, - {6,6,3,10,0}, - {7,4,2,10,1} + {4,4,1,0,1}, + {4,3,3,0,1}, + {2,3,0,1,0}, + {0,0,4,2,0}, + {3,3,0,2,1}, + {7,4,1,3,2}, + {7,2,3,3,1}, + {6,6,0,5,3}, + {6,6,3,6,0}, + {7,4,2,6,1} }; // ********************************************************************* @@ -319,12 +319,12 @@ static const fall_instr_let a54[10] = { // ********************************************************************* static const fall_instr_let a55[6] = { - {0,0,2,16,0}, - {0,5,3,14,0}, - {2,5,4,12,0}, - {2,6,2,11,3}, - {0,0,0,10,0}, - {3,1,2,9,0}, + {0,0,2,0,0}, + {0,5,3,2,0}, + {2,5,4,4,0}, + {2,6,2,5,3}, + {0,0,0,6,0}, + {3,1,2,7,0}, }; // ********************************************************************* @@ -332,14 +332,14 @@ static const fall_instr_let a55[6] = { // ********************************************************************* static const fall_instr_let a56[8] = { - {5,1,0,16,1}, - {4,4,3,16,1}, - {2,2,0,14,0}, - {1,2,4,14,0}, - {0,5,2,13,0}, - {0,6,0,11,0}, - {0,0,4,11,0}, - {3,1,1,9,0} + {5,1,0,0,1}, + {4,4,3,0,1}, + {2,2,0,2,0}, + {1,2,4,2,0}, + {0,5,2,3,0}, + {0,6,0,5,0}, + {0,0,4,5,0}, + {3,1,1,7,0} }; // ********************************************************************* @@ -347,13 +347,13 @@ static const fall_instr_let a56[8] = { // ********************************************************************* static const fall_instr_let a57[7] = { - {2,3,4,16,0}, - {2,2,4,15,2}, - {3,7,1,12,0}, - {6,6,4,12,3}, - {7,5,0,11,0}, - {7,4,4,10,1}, - {1,1,1,10,1} + {2,3,4,0,0}, + {2,2,4,1,2}, + {3,7,1,4,0}, + {6,6,4,4,3}, + {7,5,0,5,0}, + {7,4,4,6,1}, + {1,1,1,6,1} }; // ********************************************************************* @@ -361,8 +361,8 @@ static const fall_instr_let a57[7] = { // ********************************************************************* static const fall_instr_let a58[2] = { - {0,1,2,15,0}, - {0,6,2,11,0} + {0,1,2,1,0}, + {0,6,2,5,0} }; // ********************************************************************* @@ -370,9 +370,9 @@ static const fall_instr_let a58[2] = { // ********************************************************************* static const fall_instr_let a59[3] = { - {7,3,1,16,3}, - {7,4,2,15,2}, - {0,2,2,11,0} + {7,3,1,0,3}, + {7,4,2,1,2}, + {0,2,2,5,0} }; // ********************************************************************* @@ -380,11 +380,11 @@ static const fall_instr_let a59[3] = { // ********************************************************************* static const fall_instr_let a60[5] = { - {7,6,3,16,0}, - {7,1,1,15,2}, - {0,3,0,13,0}, - {7,2,1,11,3}, - {7,4,3,10,1} + {7,6,3,0,0}, + {7,1,1,1,2}, + {0,3,0,3,0}, + {7,2,1,5,3}, + {7,4,3,6,1} }; @@ -393,10 +393,10 @@ static const fall_instr_let a60[5] = { // ********************************************************************* static const fall_instr_let a61[4] = { - {1,1,2,15,3}, - {1,2,1,15,1}, - {1,3,2,11,3}, - {1,5,1,11,1} + {1,1,2,1,3}, + {1,2,1,1,1}, + {1,3,2,5,3}, + {1,5,1,5,1} }; @@ -405,11 +405,11 @@ static const fall_instr_let a61[4] = { // ********************************************************************* static const fall_instr_let a62[5] = { - {7,4,1,16,3}, - {7,2,3,15,1}, - {0,5,4,13,0}, - {7,3,3,11,0}, - {7,1,1,10,2} + {7,4,1,0,3}, + {7,2,3,1,1}, + {0,5,4,3,0}, + {7,3,3,5,0}, + {7,1,1,6,2} }; // ********************************************************************* @@ -417,12 +417,12 @@ static const fall_instr_let a62[5] = { // ********************************************************************* static const fall_instr_let a63[6] = { - {7,1,2,16,3}, - {4,3,2,14,1}, - {2,2,4,12,0}, - {2,6,2,11,3}, - {0,4,0,11,0}, - {3,5,1,9,0} + {7,1,2,0,3}, + {4,3,2,2,1}, + {2,2,4,4,0}, + {2,6,2,5,3}, + {0,4,0,5,0}, + {3,5,1,7,0} }; @@ -431,14 +431,14 @@ static const fall_instr_let a63[6] = { // ********************************************************************* static const fall_instr_let a64[8] = { - {6,2,1,16,0}, - {6,1,3,16,2}, - {1,3,0,15,0}, - {1,4,2,13,1}, - {3,5,0,12,1}, - {7,6,1,10,1}, - {6,3,2,10,0}, - {1,2,4,12,2} + {6,2,1,0,0}, + {6,1,3,0,2}, + {1,3,0,1,0}, + {1,4,2,3,1}, + {3,5,0,4,1}, + {7,6,1,6,1}, + {6,3,2,6,0}, + {1,2,4,4,2} }; @@ -447,15 +447,15 @@ static const fall_instr_let a64[8] = { // ********************************************************************* static const fall_instr_let a65[9] = { - {0,2,0,16,0}, - {0,1,4,16,0}, - {5,5,3,14,1}, - {4,2,0,14,1}, - {4,1,4,13,0}, - {5,0,0,13,0}, - {4,3,4,11,0}, - {5,2,0,11,0}, - {0,1,2,10,0} + {0,2,0,0,0}, + {0,1,4,0,0}, + {5,5,3,2,1}, + {4,2,0,2,1}, + {4,1,4,3,0}, + {5,0,0,3,0}, + {4,3,4,5,0}, + {5,2,0,5,0}, + {0,1,2,6,0} }; @@ -464,15 +464,15 @@ static const fall_instr_let a65[9] = { // ********************************************************************* static const fall_instr_let a66[9] = { - {2,7,0,16,0}, - {1,6,2,16,3}, - {4,3,4,15,0}, - {2,1,0,15,2}, - {2,4,0,13,3}, - {5,1,3,13,0}, - {0,7,0,11,0}, - {4,0,4,11,0}, - {3,3,0,9,0} + {2,7,0,0,0}, + {1,6,2,0,3}, + {4,3,4,1,0}, + {2,1,0,1,2}, + {2,4,0,3,3}, + {5,1,3,3,0}, + {0,7,0,5,0}, + {4,0,4,5,0}, + {3,3,0,7,0} }; @@ -481,14 +481,14 @@ static const fall_instr_let a66[9] = { // ********************************************************************* static const fall_instr_let a67[8] = { - {6,5,1,16,0}, - {6,3,3,16,2}, - {7,1,0,15,3}, - {5,7,0,14,0}, - {7,6,0,12,1}, - {6,3,0,10,0}, - {7,6,2,10,2}, - {7,7,4,10,0} + {6,5,1,0,0}, + {6,3,3,0,2}, + {7,1,0,1,3}, + {5,7,0,2,0}, + {7,6,0,4,1}, + {6,3,0,6,0}, + {7,6,2,6,2}, + {7,7,4,6,0} }; // ********************************************************************* @@ -496,15 +496,15 @@ static const fall_instr_let a67[8] = { // ********************************************************************* static const fall_instr_let a68[9] = { - {3,7,0,16,1}, - {0,2,1,16,0}, - {5,3,3,16,0}, - {6,5,4,14,3}, - {1,1,0,14,2}, - {6,2,4,12,1}, - {7,5,0,11,0}, - {7,3,2,10,3}, - {6,4,0,10,2} + {3,7,0,0,1}, + {0,2,1,0,0}, + {5,3,3,0,0}, + {6,5,4,2,3}, + {1,1,0,2,2}, + {6,2,4,4,1}, + {7,5,0,5,0}, + {7,3,2,6,3}, + {6,4,0,6,2} }; // ********************************************************************* @@ -512,15 +512,15 @@ static const fall_instr_let a68[9] = { // ********************************************************************* static const fall_instr_let a69[9] = { - {0,6,4,16,0}, - {3,2,0,16,0}, - {3,3,0,15,0}, - {4,4,0,14,1}, - {2,1,1,13,3}, - {2,6,0,13,2}, - {3,0,0,10,0}, - {3,4,0,9,0}, - {0,2,4,10,0} + {0,6,4,0,0}, + {3,2,0,0,0}, + {3,3,0,1,0}, + {4,4,0,2,1}, + {2,1,1,3,3}, + {2,6,0,3,2}, + {3,0,0,6,0}, + {3,4,0,7,0}, + {0,2,4,6,0} }; @@ -529,13 +529,13 @@ static const fall_instr_let a69[9] = { // ********************************************************************* static const fall_instr_let a70[7] = { - {2,1,0,16,0}, - {3,2,0,15,1}, - {1,3,1,13,0}, - {5,4,2,13,1}, - {5,5,0,11,0}, - {0,6,2,10,2}, - {0,4,4,10,0} + {2,1,0,0,0}, + {3,2,0,1,1}, + {1,3,1,3,0}, + {5,4,2,3,1}, + {5,5,0,5,0}, + {0,6,2,6,2}, + {0,4,4,6,0} }; // ********************************************************************* @@ -543,14 +543,14 @@ static const fall_instr_let a70[7] = { // ********************************************************************* static const fall_instr_let a71[8] = { - {6,7,1,16,0}, - {7,4,3,16,2}, - {4,2,4,15,0}, - {3,1,0,15,1}, - {3,0,1,15,1}, - {0,2,0,11,2}, - {6,6,3,10,0}, - {6,7,1,10,2} + {6,7,1,0,0}, + {7,4,3,0,2}, + {4,2,4,1,0}, + {3,1,0,1,1}, + {3,0,1,1,1}, + {0,2,0,5,2}, + {6,6,3,6,0}, + {6,7,1,6,2} }; // ********************************************************************* @@ -558,15 +558,15 @@ static const fall_instr_let a71[8] = { // ********************************************************************* static const fall_instr_let a72[9] = { - {0,6,0,16,0}, - {1,5,4,16,0}, - {1,2,0,14,0}, - {1,1,4,15,2}, - {3,7,1,13,1}, - {0,3,2,13,2}, - {3,4,4,12,1}, - {3,5,5,12,1}, - {2,1,0,11,2} + {0,6,0,0,0}, + {1,5,4,0,0}, + {1,2,0,2,0}, + {1,1,4,1,2}, + {3,7,1,3,1}, + {0,3,2,3,2}, + {3,4,4,4,1}, + {3,5,5,4,1}, + {2,1,0,5,2} }; // ********************************************************************* @@ -574,14 +574,14 @@ static const fall_instr_let a72[9] = { // ********************************************************************* static const fall_instr_let a73[8] = { - {6,5,0,16,0}, - {4,1,2,16,0}, - {0,2,4,16,0}, - {4,7,2,14,0}, - {6,6,2,12,3}, - {0,2,4,10,0}, - {7,1,0,10,0}, - {6,3,1,10,2} + {6,5,0,0,0}, + {4,1,2,0,0}, + {0,2,4,0,0}, + {4,7,2,2,0}, + {6,6,2,4,3}, + {0,2,4,6,0}, + {7,1,0,6,0}, + {6,3,1,6,2} }; // ********************************************************************* @@ -589,13 +589,13 @@ static const fall_instr_let a73[8] = { // ********************************************************************* static const fall_instr_let a74[7] = { - {1,7,1,16,3}, - {6,2,0,16,1}, - {6,3,3,15,3}, - {6,4,3,13,1}, - {6,2,4,11,1}, - {0,6,2,10,0}, - {0,1,0,10,0} + {1,7,1,0,3}, + {6,2,0,0,1}, + {6,3,3,1,3}, + {6,4,3,3,1}, + {6,2,4,5,1}, + {0,6,2,6,0}, + {0,1,0,6,0} }; // ********************************************************************* @@ -603,15 +603,15 @@ static const fall_instr_let a74[7] = { // ********************************************************************* static const fall_instr_let a75[9] = { - {0,2,4,16,0}, - {3,6,0,16,1}, - {2,2,1,16,2}, - {6,7,3,15,1}, - {0,5,1,13,0}, - {3,4,0,12,1}, - {1,2,1,11,0}, - {7,0,3,11,1}, - {7,1,4,10,2} + {0,2,4,0,0}, + {3,6,0,0,1}, + {2,2,1,0,2}, + {6,7,3,1,1}, + {0,5,1,3,0}, + {3,4,0,4,1}, + {1,2,1,5,0}, + {7,0,3,5,1}, + {7,1,4,6,2} }; // ********************************************************************* @@ -619,12 +619,12 @@ static const fall_instr_let a75[9] = { // ********************************************************************* static const fall_instr_let a76[6] = { - {1,3,3,16,3}, - {1,1,2,16,1}, - {0,0,0,16,0}, - {2,4,0,14,0}, - {2,2,0,13,2}, - {0,6,0,10,0} + {1,3,3,0,3}, + {1,1,2,0,1}, + {0,0,0,0,0}, + {2,4,0,2,0}, + {2,2,0,3,2}, + {0,6,0,6,0} }; // ********************************************************************* @@ -632,15 +632,15 @@ static const fall_instr_let a76[6] = { // ********************************************************************* static const fall_instr_let a77[9] = { - {1,0,0,16,0}, - {2,1,4,16,0}, - {1,3,0,15,2}, - {2,3,4,15,2}, - {0,5,2,13,0}, - {4,6,0,12,1}, - {5,2,3,12,3}, - {6,2,4,11,3}, - {6,1,0,11,1} + {1,0,0,0,0}, + {2,1,4,0,0}, + {1,3,0,1,2}, + {2,3,4,1,2}, + {0,5,2,3,0}, + {4,6,0,4,1}, + {5,2,3,4,3}, + {6,2,4,5,3}, + {6,1,0,5,1} }; // ********************************************************************* @@ -648,15 +648,15 @@ static const fall_instr_let a77[9] = { // ********************************************************************* static const fall_instr_let a78[9] = { - {1,6,0,16,0}, - {2,1,4,16,0}, - {1,3,0,15,2}, - {2,0,4,15,2}, - {4,4,2,13,0}, - {2,6,0,12,0}, - {1,1,4,12,0}, - {1,2,4,11,2}, - {2,4,0,11,2} + {1,6,0,0,0}, + {2,1,4,0,0}, + {1,3,0,1,2}, + {2,0,4,1,2}, + {4,4,2,3,0}, + {2,6,0,4,0}, + {1,1,4,4,0}, + {1,2,4,5,2}, + {2,4,0,5,2} }; @@ -665,15 +665,15 @@ static const fall_instr_let a78[9] = { // ********************************************************************* static const fall_instr_let a79[9] = { - {4,1,0,16,0}, - {5,0,4,16,0}, - {0,4,2,16,0}, - {6,4,0,14,3}, - {6,5,4,14,1}, - {6,6,0,12,1}, - {6,2,4,12,3}, - {0,1,3,10,0}, - {0,4,1,10,0} + {4,1,0,0,0}, + {5,0,4,0,0}, + {0,4,2,0,0}, + {6,4,0,2,3}, + {6,5,4,2,1}, + {6,6,0,4,1}, + {6,2,4,4,3}, + {0,1,3,6,0}, + {0,4,1,6,0} }; @@ -682,14 +682,14 @@ static const fall_instr_let a79[9] = { // ********************************************************************* static const fall_instr_let a80[8] = { - {0,6,0,16,0}, - {4,2,0,14,1}, - {5,4,2,13,3}, - {7,5,4,12,0}, - {6,0,0,13,1}, - {4,1,0,11,0}, - {7,2,4,11,2}, - {3,4,1,9,0} + {0,6,0,0,0}, + {4,2,0,2,1}, + {5,4,2,3,3}, + {7,5,4,4,0}, + {6,0,0,3,1}, + {4,1,0,5,0}, + {7,2,4,5,2}, + {3,4,1,7,0} }; // ********************************************************************* @@ -697,15 +697,15 @@ static const fall_instr_let a80[8] = { // ********************************************************************* static const fall_instr_let a81[9] = { - {5,2,3,16,1}, - {4,0,1,15,1}, - {7,3,4,14,0}, - {0,5,0,14,0}, - {6,6,4,13,3}, - {0,3,0,12,0}, - {7,1,4,11,1}, - {6,2,0,10,0}, - {6,5,2,10,2} + {5,2,3,0,1}, + {4,0,1,1,1}, + {7,3,4,2,0}, + {0,5,0,2,0}, + {6,6,4,3,3}, + {0,3,0,4,0}, + {7,1,4,5,1}, + {6,2,0,6,0}, + {6,5,2,6,2} }; // ********************************************************************* @@ -713,15 +713,15 @@ static const fall_instr_let a81[9] = { // ********************************************************************* static const fall_instr_let a82[9] = { - {0,2,4,16,0}, - {0,3,0,16,0}, - {2,1,4,14,2}, - {1,0,1,14,1}, - {2,6,0,14,2}, - {7,1,4,11,3}, - {7,0,0,11,3}, - {7,4,0,10,1}, - {2,5,2,10,3} + {0,2,4,0,0}, + {0,3,0,0,0}, + {2,1,4,2,2}, + {1,0,1,2,1}, + {2,6,0,2,2}, + {7,1,4,5,3}, + {7,0,0,5,3}, + {7,4,0,6,1}, + {2,5,2,6,3} }; // ********************************************************************* @@ -729,15 +729,15 @@ static const fall_instr_let a82[9] = { // ********************************************************************* static const fall_instr_let a83[9] = { - {6,2,0,16,2}, - {6,7,2,16,0}, - {7,3,4,15,3}, - {0,5,3,14,0}, - {1,6,2,13,1}, - {6,0,0,13,3}, - {5,1,0,11,0}, - {0,1,2,10,0}, - {7,2,4,10,0} + {6,2,0,0,2}, + {6,7,2,0,0}, + {7,3,4,1,3}, + {0,5,3,2,0}, + {1,6,2,3,1}, + {6,0,0,3,3}, + {5,1,0,5,0}, + {0,1,2,6,0}, + {7,2,4,6,0} }; // ********************************************************************* @@ -745,12 +745,12 @@ static const fall_instr_let a83[9] = { // ********************************************************************* static const fall_instr_let a84[6] = { - {0,3,2,16,0}, - {3,2,2,14,1}, - {3,1,3,14,1}, - {2,5,2,10,1}, - {2,6,3,10,3}, - {0,1,0,10,0} + {0,3,2,0,0}, + {3,2,2,2,1}, + {3,1,3,2,1}, + {2,5,2,6,1}, + {2,6,3,6,3}, + {0,1,0,6,0} }; // ********************************************************************* @@ -758,15 +758,15 @@ static const fall_instr_let a84[6] = { // ********************************************************************* static const fall_instr_let a85[9] = { - {6,1,4,16,1}, - {0,4,2,16,0}, - {6,3,0,16,3}, - {4,5,4,14,0}, - {5,6,0,14,0}, - {6,1,4,12,3}, - {6,0,0,12,1}, - {7,4,4,10,1}, - {7,5,0,10,2} + {6,1,4,0,1}, + {0,4,2,0,0}, + {6,3,0,0,3}, + {4,5,4,2,0}, + {5,6,0,2,0}, + {6,1,4,4,3}, + {6,0,0,4,1}, + {7,4,4,6,1}, + {7,5,0,6,2} }; // ********************************************************************* @@ -774,16 +774,16 @@ static const fall_instr_let a85[9] = { // ********************************************************************* static const fall_instr_let a86[10] = { - {6,0,1,16,3}, - {7,1,3,16,1}, - {6,4,3,14,0}, - {1,0,1,14,1}, - {2,6,0,14,2}, - {7,1,4,13,2}, - {7,3,0,11,3}, - {7,4,4,11,0}, - {7,3,4,10,2}, - {7,5,0,10,1} + {6,0,1,0,3}, + {7,1,3,0,1}, + {6,4,3,2,0}, + {1,0,1,2,1}, + {2,6,0,2,2}, + {7,1,4,3,2}, + {7,3,0,5,3}, + {7,4,4,5,0}, + {7,3,4,6,2}, + {7,5,0,6,1} }; @@ -792,14 +792,14 @@ static const fall_instr_let a86[10] = { // ********************************************************************* static const fall_instr_let a87[8] = { - {2,0,1,16,2}, - {1,1,3,16,2}, - {3,4,5,15,1}, - {3,3,0,15,1}, - {2,1,4,13,2}, - {1,2,0,13,2}, - {0,6,0,10,0}, - {0,4,4,10,0} + {2,0,1,0,2}, + {1,1,3,0,2}, + {3,4,5,1,1}, + {3,3,0,1,1}, + {2,1,4,3,2}, + {1,2,0,3,2}, + {0,6,0,6,0}, + {0,4,4,6,0} }; @@ -808,13 +808,13 @@ static const fall_instr_let a87[8] = { // ********************************************************************* static const fall_instr_let a88[7] = { - {7,6,0,16,1}, - {7,7,4,16,2}, - {3,2,1,14,0}, - {0,5,2,13,0}, - {3,6,1,11,0}, - {7,3,4,10,3}, - {7,1,0,10,0} + {7,6,0,0,1}, + {7,7,4,0,2}, + {3,2,1,2,0}, + {0,5,2,3,0}, + {3,6,1,5,0}, + {7,3,4,6,3}, + {7,1,0,6,0} }; // ********************************************************************* @@ -822,13 +822,13 @@ static const fall_instr_let a88[7] = { // ********************************************************************* static const fall_instr_let a89[7] = { - {0,2,2,16,0}, - {1,7,2,14,0}, - {7,6,3,13,1}, - {6,5,3,11,0}, - {7,6,4,10,2}, - {6,2,1,12,1}, - {2,1,0,11,2} + {0,2,2,0,0}, + {1,7,2,2,0}, + {7,6,3,3,1}, + {6,5,3,5,0}, + {7,6,4,6,2}, + {6,2,1,4,1}, + {2,1,0,5,2} }; // ********************************************************************* @@ -836,15 +836,15 @@ static const fall_instr_let a89[7] = { // ********************************************************************* static const fall_instr_let a90[9] = { - {2,5,0,16,1}, - {1,3,3,16,3}, - {3,1,1,15,0}, - {0,0,2,14,0}, - {7,6,3,13,2}, - {1,1,4,11,2}, - {4,7,3,11,0}, - {7,6,1,10,3}, - {7,2,0,10,1} + {2,5,0,0,1}, + {1,3,3,0,3}, + {3,1,1,1,0}, + {0,0,2,2,0}, + {7,6,3,3,2}, + {1,1,4,5,2}, + {4,7,3,5,0}, + {7,6,1,6,3}, + {7,2,0,6,1} }; // holds the number of blocks in each character diff --git a/src/TetrisMatrixDraw.cpp b/src/TetrisMatrixDraw.cpp index fabd193..cb0c291 100644 --- a/src/TetrisMatrixDraw.cpp +++ b/src/TetrisMatrixDraw.cpp @@ -533,13 +533,13 @@ void TetrisMatrixDraw::setText(String txt, bool forceRefresh) } } -bool TetrisMatrixDraw::drawText(int x, int yFinish) +bool TetrisMatrixDraw::drawText(int x, int yFinish, int yDropDistance) { // For each number position bool finishedAnimating = true; int scaledYOffset = (this->scale > 1) ? this->scale : 1; - int y = yFinish - (TETRIS_Y_DROP_DEFAULT * this->scale); + int y = yFinish - (yDropDistance * this->scale); // For each number position for (int numpos = 0; numpos < this->sizeOfValue; numpos++) @@ -558,33 +558,33 @@ bool TetrisMatrixDraw::drawText(int x, int yFinish) uint8_t rotations = current_fall.num_rot; if (rotations == 1) { - if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 2)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 2)) { rotations = 0; } } if (rotations == 2) { - if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 3)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 3)) { rotations = 0; } - if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 3 * 2)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 3 * 2)) { rotations = 1; } } if (rotations == 3) { - if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 4)) { rotations = 0; } - if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4 * 2)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 4 * 2)) { rotations = 1; } - if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4 * 3)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 4 * 3)) { rotations = 2; } @@ -606,7 +606,7 @@ bool TetrisMatrixDraw::drawText(int x, int yFinish) //drawShape(current_fall.blocktype, this->tetrisColors[current_fall.color], x + current_fall.x_pos + numstates[numpos].x_shift, y + numstates[numpos].fallindex - 1, rotations); numstates[numpos].fallindex++; - if (numstates[numpos].fallindex > current_fall.y_stop) + if (numstates[numpos].fallindex > (yDropDistance - current_fall.y_stop_offset)) { numstates[numpos].fallindex = 0; numstates[numpos].blockindex++; @@ -623,14 +623,14 @@ bool TetrisMatrixDraw::drawText(int x, int yFinish) drawShape(fallen_block.blocktype, this->tetrisColors[fallen_block.color], x + fallen_block.x_pos + numstates[numpos].x_shift, - y + fallen_block.y_stop - 1, + y + (yDropDistance - fallen_block.y_stop_offset) - 1, fallen_block.num_rot); } else { drawLargerShape(this->scale, fallen_block.blocktype, this->tetrisColors[fallen_block.color], x + (fallen_block.x_pos * this->scale) + numstates[numpos].x_shift, - y + (fallen_block.y_stop * scaledYOffset) - scaledYOffset, + y + ((yDropDistance - fallen_block.y_stop_offset) * scaledYOffset) - scaledYOffset, fallen_block.num_rot); } //drawShape(fallen_block.blocktype, this->tetrisColors[fallen_block.color], x + fallen_block.x_pos + numstates[numpos].x_shift, y + fallen_block.y_stop - 1, fallen_block.num_rot); @@ -664,7 +664,7 @@ bool TetrisMatrixDraw::drawNumbers(int x, int yFinish, bool displayColon, int yD uint8_t rotations = current_fall.num_rot; if (rotations == 1) { - if (numstates[numpos].fallindex < (int)(((yDropDistance - current_fall.y_stop_offset)) / 2)) + if (numstates[numpos].fallindex < (int)((yDropDistance - current_fall.y_stop_offset) / 2)) { rotations = 0; } @@ -754,9 +754,9 @@ bool TetrisMatrixDraw::drawNumbers(int x, int yFinish, bool displayColon, int yD void TetrisMatrixDraw::drawColon(int x, int y, uint16_t colonColour){ int colonSize = 2 * this->scale; - int xColonPos = x + (TETRIS_DISTANCE_BETWEEN_DIGITS * 2 * this->scale); - display->fillRect(xColonPos, y + (12 * this->scale), colonSize, colonSize, colonColour); - display->fillRect(xColonPos, y + (8 * this->scale), colonSize, colonSize, colonColour); + int xColonPos = x + (TETRIS_DISTANCE_BETWEEN_DIGITS * 2 * this->scale); + drawLargerBlock(xColonPos, y + (12 * this->scale), colonSize, colonColour); + drawLargerBlock(xColonPos, y + (8 * this->scale), colonSize, colonColour); } int TetrisMatrixDraw::calculateWidth(){ diff --git a/src/TetrisMatrixDraw.h b/src/TetrisMatrixDraw.h index d4442ff..b3ba35f 100644 --- a/src/TetrisMatrixDraw.h +++ b/src/TetrisMatrixDraw.h @@ -48,7 +48,7 @@ class TetrisMatrixDraw TetrisMatrixDraw (Adafruit_GFX &display); Adafruit_GFX *display; bool drawNumbers(int x = 0, int y = 0, bool displayColon = false, int yDropDistance = TETRIS_Y_DROP_DEFAULT); - bool drawText(int x = 0, int y = 0); + bool drawText(int x = 0, int y = 0, int yDropDistance = TETRIS_Y_DROP_DEFAULT); void drawChar(String letter, uint8_t x, uint8_t y, uint16_t color); void drawShape(int blocktype, uint16_t color, int x_pos, int y_pos, int num_rot); void drawLargerShape(int scale, int blocktype, uint16_t color, int x_pos, int y_pos, int num_rot);