Download the attached Pumpktris.ino.zip, unzip it, and open the file in the Arduino development environment. Compile and upload it to your Arduino. You should now be able to play on the mini LED matrix you set up in the previous step. I've tried to comment the code as much as possible, but here's a general overview of the main processes:There are seven tetrominos, each with 4 pixels, and each with four possible rotations. We store all of this in a multi-dimensional array: the first dimension consisting of the seven shapes, the second dimension containing the four rotations for each shape, the third containing four pixel descriptions that each consist of an X and Y coordinate.For example, this describes the "T" shape:

/* T */ {

/* angle 0 */ { {0,1}, {1,1}, {2,1}, {1,2} },

/* angle 90 */ { {1,0}, {1,1}, {2,1}, {1,2} },

/* angle 180 */ { {1,0}, {0,1}, {1,1}, {2,1} },

/* angle 270 */ { {1,0}, {0,1}, {1,1}, {1,2} }

}

byte sampleGrid[16]=

{

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00000000,

B00100000,

B00111000

};

To keep track of the piece currently in play, the program maintains an activePiece variable. This is the index of the active shape in the highest level of the array. It also keeps a rotation variable containing the index of the current rotation. An xOffset variable tracks how far left or right (0-7) each piece is, and yOffset tracks how far down (0-15) the board it's fallen. To draw the active piece the program adds the X and Y offset values to the X and Y coordinates of each pixel pulled from the current rotation of the selected piece.The program uses a 16 byte array to keep track of the fixed pieces, with each byte representing a row. For example, the array below would represent an L shape sitting in the center of the bottom two rows (as indicated by the 1s in the last two bytes):When an attempt is made to move the active piece, the program first checks the new position against the array of fixed pieces. If there are no collisions, the move is allowed and the matrix is redrawn. If a collision is detected while attempting to move left, right, or to rotate, the action is prohibited. If a collision is detected while attempting to drop a piece, the piece becomes fixed in its position and is added to the array of fixed pixels.The pace of the game is controlled by the gravityTrigger and stepCounter variables. Every loop of the program increments stepCounter, and every time stepCounter reaches the count stored in gravityTrigger, it drops the active piece one level.As the game progresses, gravityTrigger is decreased so that the active piece drops more and more frequently until finally it's dropping in every loop of the program.Every time an active piece is fixed to the grid the program checks for full bytes/rows (B11111111). If it finds any, it blinks them off and on three times, then removes them and drops the rows above to fill the gap.If the pieces aren't falling from top to bottom, but instead go from side to side, change the value passed in the lines "matrixTop.setRotation(1);" and/or "matrixBottom.setRotation(1);" in the "setup()" loop.If the pieces start in the wrong matrix, switch the physical location of each matrix or reverse the addresses declared in the "matrixTop.begin(0x70);" and "matrixBottom.begin(0x71);" lines of the "setup()" loop.If some rows or columns don't light, wiggle the mini LED matrix in the female headers. They may not be making good contact.