William Etter / Mbed 2 deprecated LEDTable

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers tunnel.h Source File

tunnel.h

00001 int tunnel_time;
00002 char ledtable_tunnel [16] [32];
00003 char tunnel_val;    // Center of Tunnel
00004 
00005 /*************************************************************************
00006 Function Headers
00007 **************************************************************************/
00008 void tunnel_init(void);
00009 void tunnel_update(void);
00010 
00011 void tunnel_init(void){
00012     tunnel_time = tabletimer.read_ms();
00013     tunnel_val = 7;
00014     
00015 }
00016 
00017 void tunnel_update(void){
00018     int tunnel_move;
00019     if((tabletimer.read_ms() - tunnel_time)>tunnel_update_time){
00020         // Update the matrix mapping
00021         
00022         // Shift values right
00023         for(int col = 31; col >0; col--){
00024             ledtable_tunnel[0][col] = ledtable[0][col-1];
00025             ledtable_tunnel[1][col] = ledtable[1][col-1];
00026             ledtable_tunnel[2][col] = ledtable[2][col-1];
00027             ledtable_tunnel[3][col] = ledtable[3][col-1];
00028             ledtable_tunnel[4][col] = ledtable[4][col-1];
00029             ledtable_tunnel[5][col] = ledtable[5][col-1];
00030             ledtable_tunnel[6][col] = ledtable[6][col-1];
00031             ledtable_tunnel[7][col] = ledtable[7][col-1];
00032             ledtable_tunnel[8][col] = ledtable[8][col-1];
00033             ledtable_tunnel[9][col] = ledtable[9][col-1];
00034             ledtable_tunnel[10][col] = ledtable[10][col-1];
00035             ledtable_tunnel[11][col] = ledtable[11][col-1];
00036             ledtable_tunnel[12][col] = ledtable[12][col-1];
00037             ledtable_tunnel[13][col] = ledtable[13][col-1];
00038             ledtable_tunnel[14][col] = ledtable[14][col-1];
00039             ledtable_tunnel[15][col] = ledtable[15][col-1]; 
00040         }
00041         // Update first column
00042         if(tunnel_val == 12){
00043             tunnel_move = rand()%2;
00044         }
00045         else if(tunnel_val == 2){
00046             tunnel_move = (rand()%2)+1;
00047         }
00048         else{   
00049             tunnel_move = rand()%3;
00050         }
00051         switch(tunnel_move){
00052             case 0:
00053                 // Move tunnel down
00054                 tunnel_val -= 1;
00055                 break;
00056             case 1:
00057                 // Keep tunnel the same
00058                 break;
00059             case 2:
00060                 // Move tunnel up
00061                 tunnel_val += 1;
00062             default:
00063                 break;
00064         } 
00065         
00066         for(int tunnel = 0; tunnel < 16; tunnel ++){
00067             if(tunnel < (tunnel_val-2)){
00068                 ledtable_tunnel[tunnel][0] = 60;
00069             }
00070             else if(tunnel > (tunnel_val+2)){
00071                 ledtable_tunnel[tunnel][0] = 60;
00072             }
00073             else{
00074                 ledtable_tunnel[tunnel][0] = 0;
00075             }
00076         }
00077         
00078         // Update table
00079         for(int i = 0; i <16; i++){
00080             for(int j = 0; j <32; j++){
00081                 ledtable[i][j] = ledtable_tunnel[i][j];
00082             }
00083         }
00084         tunnel_time = tabletimer.read_ms();
00085     }
00086 }