William Etter / Mbed 2 deprecated LEDTable

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers matrix.h Source File

matrix.h

00001 /* Matrix Table */
00002 int matrix_time;
00003 int matrix_leader_time;
00004 int matrix_leader_prev_time;
00005 char ledtable_matrix [16] [32];
00006 
00007 
00008 /*************************************************************************
00009 Function Headers
00010 **************************************************************************/
00011 void matrix_init(void);
00012 void matrix_update(void);
00013 void matrix_leader(void);
00014 
00015 
00016 void matrix_init(void){
00017     matrix_leader_time = tabletimer.read_ms();
00018     matrix_leader_prev_time = matrix_leader_time;
00019     matrix_time = tabletimer.read_ms();
00020 }
00021 
00022 
00023 
00024 void matrix_update(void){
00025     
00026     if((tabletimer.read_ms() - matrix_time)>matrix_update_time){
00027         // Update the matrix mapping
00028         
00029         // Shift values right
00030         for(int col = 31; col >0; col--){
00031             ledtable_matrix[0][col] = ledtable[0][col-1];
00032             ledtable_matrix[1][col] = ledtable[1][col-1];
00033             ledtable_matrix[2][col] = ledtable[2][col-1];
00034             ledtable_matrix[3][col] = ledtable[3][col-1];
00035             ledtable_matrix[4][col] = ledtable[4][col-1];
00036             ledtable_matrix[5][col] = ledtable[5][col-1];
00037             ledtable_matrix[6][col] = ledtable[6][col-1];
00038             ledtable_matrix[7][col] = ledtable[7][col-1];
00039             ledtable_matrix[8][col] = ledtable[8][col-1];
00040             ledtable_matrix[9][col] = ledtable[9][col-1];
00041             ledtable_matrix[10][col] = ledtable[10][col-1];
00042             ledtable_matrix[11][col] = ledtable[11][col-1];
00043             ledtable_matrix[12][col] = ledtable[12][col-1];
00044             ledtable_matrix[13][col] = ledtable[13][col-1];
00045             ledtable_matrix[14][col] = ledtable[14][col-1];
00046             ledtable_matrix[15][col] = ledtable[15][col-1]; 
00047         }
00048         // Update first column
00049         for(int row = 0; row <16; row++){
00050             if(ledtable[row][0]>=matrix_diff_value){
00051                 ledtable_matrix[row][0] = ledtable[row][0]-matrix_diff_value;
00052             }
00053             else{
00054                 ledtable_matrix[row][0] = 0;
00055             }
00056         }
00057         // Update table
00058         for(int i = 0; i <16; i++){
00059             for(int j = 0; j <32; j++){
00060                 ledtable[i][j] = ledtable_matrix[i][j];
00061             }
00062         }
00063         // Check if need to add new leaders
00064         matrix_leader_time = tabletimer.read_ms();
00065         if((matrix_leader_time - matrix_leader_prev_time) > leader_time_diff){
00066             matrix_leader();
00067         }
00068         matrix_time = tabletimer.read_ms();
00069         
00070     }   
00071 }
00072 
00073 
00074 void matrix_leader(void){
00075     int leader_num;
00076     if((rand()%10)>leader_probabilty){
00077         leader_num = rand()%16;
00078         if(ledtable[leader_num][0] == 0){
00079             ledtable[leader_num][0] = 60;
00080         }
00081     }
00082 }