Snake game for a 5x5 LED matrix

Dependencies:   MCP23S17 mbed

Revision:
2:9c075a0a6d4e
Parent:
1:5fcb94bb03db
--- a/ledCube.cpp	Thu Oct 17 04:32:58 2013 +0000
+++ b/ledCube.cpp	Thu Oct 17 22:09:22 2013 +0000
@@ -35,6 +35,7 @@
     ledArray[4][2] = new DigitalOut(P042);
     ledArray[4][3] = new DigitalOut(P043);
     ledArray[4][4] = new DigitalOut(P044);
+    spiCurrentlyLit = 0;
     //  Set all 8 Port A bits to output direction
     (*chip).direction(PORT_A, 0x00);
     //  Set all 8 Port B bits to output direction
@@ -48,7 +49,9 @@
     if(ledArray[row][column] != NULL){
         *ledArray[row][column] = 1;
     }
+    // This else handles cases where the LEDs are handled by the I/O extender
     else{
+    //printf("before on-spiCurrentlyLit: %d turn on Row: %d Col: %d \n", spiCurrentlyLit, row, column);
         if( row == 1 && column == 3){
             spiCurrentlyLit |= 0x01;   
         }
@@ -77,12 +80,15 @@
     }
 }
 
+// Turns off the LED at the specified row and column
 void ledCube::turnOffLed(char row, char column, char layer)
 {
     if(ledArray[row][column] != NULL){
         *ledArray[row][column] = 0;
     }
+    // This else handles cases where the LEDs are handled by the I/O extender
     else{
+        //printf("before: off-spiCurrentlyLit: %d turn off Row: %d Col: %d \n", spiCurrentlyLit, row, column);
         if( row == 1 && column == 3){
             spiCurrentlyLit &= ~(0x01);   
         }
@@ -111,6 +117,7 @@
     }
 }
 
+// Blinks all the LEDs to indicate losing
 void ledCube::blink()
 {
     for(char i = 0; i < 5; i++) {
@@ -118,10 +125,11 @@
             turnOnLed(i,j,0);
         }
     }
-    wait(.3);
+        wait(.3);
     for(char i = 0; i < 5; i++) {
         for(char j = 0; j < 5; j++) {
             turnOffLed(i,j,0);
         }
     }
+    wait(.3);
 }