ProjectBattleShip_FRA221 / WolfWarp
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ThreeTwoOne.cpp Source File

ThreeTwoOne.cpp

00001 #include "mbed.h"
00002 //************************ Complete to Interface ***************************
00003 // configure library with this code ****************************************
00004 SPI dot_matrix(D11,NC,D13); //mosi miso sclk
00005 DigitalOut lat(PA_12); //6
00006 DigitalOut sb(PA_11); //7
00007 DigitalOut rst(D10);
00008 BusOut open_line(D2,D3,D4,D5,D6,D7,D8,D9);
00009               //c0 c1 c2 c3 c4 c5 c6 c7 dont foget d7
00010 Serial pc(D1, D0);
00011 Timer t;
00012 
00013 int counter;
00014 int click = 0;
00015 int swap = 0;
00016 int downter = 60;
00017 uint8_t rgb[3] = {0,0,0};
00018 
00019 int main(){
00020 
00021   dot_matrix.frequency(1000000);
00022   // dot_matrix.format(6,0);
00023   uint8_t wb[3] = {255,255,255};
00024   uint8_t pic[73][8] ={
00025   {0xbd,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00026   {0xbd,0xa1,0x00,0x00,0x00,0x00,0x00,0x00},
00027   {0xbd,0xa1,0xa1,0x00,0x00,0x00,0x00,0x00},
00028   {0xbd,0xa1,0xa1,0xbd,0x00,0x00,0x00,0x00},
00029   {0xbd,0xa1,0xa1,0xbd,0xa1,0x00,0x00,0x00},
00030   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0x00,0x00},
00031   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x00},
00032   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00033 
00034   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00035   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00036   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00037   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00038   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00039   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00040   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00041   {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00042 
00043   {0x00,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00044   {0x00,0x00,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
00045   {0x00,0x00,0x00,0xbd,0xa1,0xa1,0xbd,0x81},
00046   {0x00,0x00,0x00,0x00,0xa1,0xa1,0xbd,0x81},
00047   {0x00,0x00,0x00,0x00,0x00,0xa1,0xbd,0x81},
00048   {0x00,0x00,0x00,0x00,0x00,0x00,0xbd,0x81},
00049   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81},
00050   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00051 
00052 
00053   {0xbd,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00054   {0xbd,0xa1,0x00,0x00,0x00,0x00,0x00,0x00},
00055   {0xbd,0xa1,0xa1,0x00,0x00,0x00,0x00,0x00},
00056   {0xbd,0xa1,0xa1,0xbd,0x00,0x00,0x00,0x00},
00057   {0xbd,0xa1,0xa1,0xbd,0x85,0x00,0x00,0x00},
00058   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0x00,0x00},
00059   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x00},
00060   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00061 
00062   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00063   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00064   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00065   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00066   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00067   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00068   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00069   {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00070 
00071   {0x00,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00072   {0x00,0x00,0xa1,0xbd,0x85,0x85,0xbd,0x81},
00073   {0x00,0x00,0x00,0xbd,0x85,0x85,0xbd,0x81},
00074   {0x00,0x00,0x00,0x00,0x85,0x85,0xbd,0x81},
00075   {0x00,0x00,0x00,0x00,0x00,0x85,0xbd,0x81},
00076   {0x00,0x00,0x00,0x00,0x00,0x00,0xbd,0x81},
00077   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81},
00078   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00079 
00080 
00081   {0x99,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00082   {0x99,0x9d,0x00,0x00,0x00,0x00,0x00,0x00},
00083   {0x99,0x9d,0x99,0x00,0x00,0x00,0x00,0x00},
00084   {0x99,0x9d,0x99,0x99,0x00,0x00,0x00,0x00},
00085   {0x99,0x9d,0x99,0x99,0x99,0x00,0x00,0x00},
00086   {0x99,0x9d,0x99,0x99,0x99,0x99,0x00,0x00},
00087   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x00},
00088   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00089 
00090   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00091   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00092   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00093   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00094   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00095   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00096   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00097   {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00098 
00099   {0x00,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
00100   {0x00,0x00,0x99,0x99,0x99,0x99,0xbd,0x81},
00101   {0x00,0x00,0x00,0x99,0x99,0x99,0xbd,0x81},
00102   {0x00,0x00,0x00,0x00,0x99,0x99,0xbd,0x81},
00103   {0x00,0x00,0x00,0x00,0x00,0x99,0xbd,0x81},
00104   {0x00,0x00,0x00,0x00,0x00,0x00,0xbd,0x81},
00105   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81},
00106   {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
00107 
00108   {0x00,0xef,0xa1,0xad,0xa9,0xef,0x00,0x00}
00109 
00110 
00111   };
00112   uint8_t temp;
00113   int line[8] = {1,2,4,8,16,32,64,128};
00114 
00115   rst = 1;
00116   wait(0.5);
00117   rst = 0;
00118   wait(0.5);
00119   rst = 1;
00120   wait(0.5);
00121 
00122   //dot_matrix.format(6,0);
00123   sb = 0; // 6 bit
00124   for(int i = 0; i<8; i++){
00125     dot_matrix.write(wb[0]);
00126     dot_matrix.write(wb[1]);
00127     dot_matrix.write(wb[2]);
00128 
00129   open_line = 0;
00130   // dot_matrix.format(8,0);
00131   sb = 1; // 8 bit
00132   t.start();
00133   while (1) {
00134   if(swap <= 72){
00135       for(int j=0;j<=72;j++){
00136         swap = swap + 1;
00137         for(int a=0;a<=7;a++){
00138           temp = pic[j][a];
00139           counter = counter+1;
00140             if( counter == 60 ){
00141             click = click+1;
00142             counter=0;
00143           }
00144             if(click == 0){
00145               rgb[0] = 0;
00146               rgb[1] = 0;
00147               rgb[2] = counter;
00148             }
00149             else if(click == 1){
00150               rgb[0] = 0;
00151               rgb[1] = counter;
00152               rgb[2] = 60;
00153             }
00154             else if(click == 2){
00155               rgb[0] = 0;
00156               rgb[1] = 60;
00157               rgb[2] = 60 - counter;
00158               }
00159             else if(click == 3){
00160               rgb[0] = counter;
00161               rgb[1] = 60;
00162               rgb[2] = 0;
00163             }
00164             else if(click == 4){
00165               rgb[0] = 60;
00166               rgb[1] = 60 - counter;
00167               rgb[2] = 0;
00168             }
00169             else if(click == 5){
00170               rgb[0] = 60;
00171               rgb[1] = 0;
00172               rgb[2] = counter;
00173             }
00174             else if(click == 6){
00175               rgb[0] = 60 - counter;
00176               rgb[1] = 0;
00177               rgb[2] = 60;
00178             }
00179             else if(click == 7){
00180               rgb[0] = 0;
00181               rgb[1] = 0;
00182               rgb[2] = 60;
00183               click = 1;
00184             }
00185         for(int i = 0; i<8; i++){
00186 
00187           if(temp & 0x80){
00188             dot_matrix.write(rgb[0]);
00189             dot_matrix.write(rgb[1]);
00190             dot_matrix.write(rgb[2]);
00191           }
00192           else{
00193             dot_matrix.write(0);
00194             dot_matrix.write(0);
00195             dot_matrix.write(0);
00196           }
00197           temp = temp << 1;
00198         }
00199         lat = 1;
00200         lat = 0;
00201         open_line = line[a];
00202         wait(0.0025);
00203     }
00204 
00205         //open_line = 0;
00206 
00207       }
00208     }
00209   else if(swap >=72){
00210     t.reset();
00211     t.start();
00212     if( t.read()>= 0 && t.read()<= 5 ){
00213     for(int j=0;j<=72;j++){
00214       swap = swap + 1;
00215       for(int a=0;a<=7;a++){
00216         temp = pic[72][a];
00217         counter = counter+1;
00218         if( counter == 60 ){
00219           click = click+1;
00220           counter=0;
00221         }
00222           if(click == 0){
00223             rgb[0] = 0;
00224             rgb[1] = 0;
00225             rgb[2] = counter;
00226           }
00227           else if(click == 1){
00228             rgb[0] = 0;
00229             rgb[1] = counter;
00230             rgb[2] = 60;
00231           }
00232           else if(click == 2){
00233             rgb[0] = 0;
00234             rgb[1] = 60;
00235             rgb[2] = 60 - counter;
00236             }
00237           else if(click == 3){
00238             rgb[0] = counter;
00239             rgb[1] = 60;
00240             rgb[2] = 0;
00241           }
00242           else if(click == 4){
00243             rgb[0] = 60;
00244             rgb[1] = 60 - counter;
00245             rgb[2] = 0;
00246           }
00247           else if(click == 5){
00248             rgb[0] = 60;
00249             rgb[1] = 0;
00250             rgb[2] = counter;
00251           }
00252           else if(click == 6){
00253             rgb[0] = 60 - counter;
00254             rgb[1] = 0;
00255             rgb[2] = 60;
00256           }
00257           else if(click == 7){
00258             rgb[0] = 0;
00259             rgb[1] = 0;
00260             rgb[2] = 60;
00261             click = 1;
00262           }
00263     for(int i = 0; i<8; i++){
00264 
00265       if(temp & 0x80){
00266         dot_matrix.write(rgb[0]);
00267         dot_matrix.write(rgb[1]);
00268         dot_matrix.write(rgb[2]);
00269       }
00270       else{
00271         dot_matrix.write(0);
00272         dot_matrix.write(0);
00273         dot_matrix.write(0);
00274       }
00275       temp = temp << 1;
00276     }
00277     lat = 1;
00278     lat = 0;
00279     open_line = line[a];
00280     wait(0.0025);
00281 
00282   }
00283   }
00284 }
00285 else{
00286   break;
00287 }
00288 }
00289 }
00290 }
00291 }