ProjectBattleShip_FRA221 / WolfWarp

ThreeTwoOne.cpp

Committer:
Xantares
Date:
2016-12-05
Revision:
4:82be81810ee6

File content as of revision 4:82be81810ee6:

#include "mbed.h"
//************************ Complete to Interface ***************************
// configure library with this code ****************************************
SPI dot_matrix(D11,NC,D13); //mosi miso sclk
DigitalOut lat(PA_12); //6
DigitalOut sb(PA_11); //7
DigitalOut rst(D10);
BusOut open_line(D2,D3,D4,D5,D6,D7,D8,D9);
              //c0 c1 c2 c3 c4 c5 c6 c7 dont foget d7
Serial pc(D1, D0);
Timer t;

int counter;
int click = 0;
int swap = 0;
int downter = 60;
uint8_t rgb[3] = {0,0,0};

int main(){

  dot_matrix.frequency(1000000);
  // dot_matrix.format(6,0);
  uint8_t wb[3] = {255,255,255};
  uint8_t pic[73][8] ={
  {0xbd,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0x00,0x00,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0x00,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x00},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},

  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},

  {0x00,0xa1,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0x00,0x00,0xa1,0xbd,0xa1,0xa1,0xbd,0x81},
  {0x00,0x00,0x00,0xbd,0xa1,0xa1,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0xa1,0xa1,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0xa1,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},


  {0xbd,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0x00,0x00,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0x00,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0x00,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x00,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0x00,0x00},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x00},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},

  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0xbd,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},

  {0x00,0xa1,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0x00,0x00,0xa1,0xbd,0x85,0x85,0xbd,0x81},
  {0x00,0x00,0x00,0xbd,0x85,0x85,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x85,0x85,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x85,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},


  {0x99,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
  {0x99,0x9d,0x00,0x00,0x00,0x00,0x00,0x00},
  {0x99,0x9d,0x99,0x00,0x00,0x00,0x00,0x00},
  {0x99,0x9d,0x99,0x99,0x00,0x00,0x00,0x00},
  {0x99,0x9d,0x99,0x99,0x99,0x00,0x00,0x00},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0x00,0x00},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x00},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},

  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x99,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},

  {0x00,0x9d,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x00,0x00,0x99,0x99,0x99,0x99,0xbd,0x81},
  {0x00,0x00,0x00,0x99,0x99,0x99,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x99,0x99,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x99,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0xbd,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81},
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},

  {0x00,0xef,0xa1,0xad,0xa9,0xef,0x00,0x00}


  };
  uint8_t temp;
  int line[8] = {1,2,4,8,16,32,64,128};

  rst = 1;
  wait(0.5);
  rst = 0;
  wait(0.5);
  rst = 1;
  wait(0.5);

  //dot_matrix.format(6,0);
  sb = 0; // 6 bit
  for(int i = 0; i<8; i++){
    dot_matrix.write(wb[0]);
    dot_matrix.write(wb[1]);
    dot_matrix.write(wb[2]);

  open_line = 0;
  // dot_matrix.format(8,0);
  sb = 1; // 8 bit
  t.start();
  while (1) {
  if(swap <= 72){
      for(int j=0;j<=72;j++){
        swap = swap + 1;
        for(int a=0;a<=7;a++){
          temp = pic[j][a];
          counter = counter+1;
            if( counter == 60 ){
            click = click+1;
            counter=0;
          }
            if(click == 0){
              rgb[0] = 0;
              rgb[1] = 0;
              rgb[2] = counter;
            }
            else if(click == 1){
              rgb[0] = 0;
              rgb[1] = counter;
              rgb[2] = 60;
            }
            else if(click == 2){
              rgb[0] = 0;
              rgb[1] = 60;
              rgb[2] = 60 - counter;
              }
            else if(click == 3){
              rgb[0] = counter;
              rgb[1] = 60;
              rgb[2] = 0;
            }
            else if(click == 4){
              rgb[0] = 60;
              rgb[1] = 60 - counter;
              rgb[2] = 0;
            }
            else if(click == 5){
              rgb[0] = 60;
              rgb[1] = 0;
              rgb[2] = counter;
            }
            else if(click == 6){
              rgb[0] = 60 - counter;
              rgb[1] = 0;
              rgb[2] = 60;
            }
            else if(click == 7){
              rgb[0] = 0;
              rgb[1] = 0;
              rgb[2] = 60;
              click = 1;
            }
        for(int i = 0; i<8; i++){

          if(temp & 0x80){
            dot_matrix.write(rgb[0]);
            dot_matrix.write(rgb[1]);
            dot_matrix.write(rgb[2]);
          }
          else{
            dot_matrix.write(0);
            dot_matrix.write(0);
            dot_matrix.write(0);
          }
          temp = temp << 1;
        }
        lat = 1;
        lat = 0;
        open_line = line[a];
        wait(0.0025);
    }

        //open_line = 0;

      }
    }
  else if(swap >=72){
    t.reset();
    t.start();
    if( t.read()>= 0 && t.read()<= 5 ){
    for(int j=0;j<=72;j++){
      swap = swap + 1;
      for(int a=0;a<=7;a++){
        temp = pic[72][a];
        counter = counter+1;
        if( counter == 60 ){
          click = click+1;
          counter=0;
        }
          if(click == 0){
            rgb[0] = 0;
            rgb[1] = 0;
            rgb[2] = counter;
          }
          else if(click == 1){
            rgb[0] = 0;
            rgb[1] = counter;
            rgb[2] = 60;
          }
          else if(click == 2){
            rgb[0] = 0;
            rgb[1] = 60;
            rgb[2] = 60 - counter;
            }
          else if(click == 3){
            rgb[0] = counter;
            rgb[1] = 60;
            rgb[2] = 0;
          }
          else if(click == 4){
            rgb[0] = 60;
            rgb[1] = 60 - counter;
            rgb[2] = 0;
          }
          else if(click == 5){
            rgb[0] = 60;
            rgb[1] = 0;
            rgb[2] = counter;
          }
          else if(click == 6){
            rgb[0] = 60 - counter;
            rgb[1] = 0;
            rgb[2] = 60;
          }
          else if(click == 7){
            rgb[0] = 0;
            rgb[1] = 0;
            rgb[2] = 60;
            click = 1;
          }
    for(int i = 0; i<8; i++){

      if(temp & 0x80){
        dot_matrix.write(rgb[0]);
        dot_matrix.write(rgb[1]);
        dot_matrix.write(rgb[2]);
      }
      else{
        dot_matrix.write(0);
        dot_matrix.write(0);
        dot_matrix.write(0);
      }
      temp = temp << 1;
    }
    lat = 1;
    lat = 0;
    open_line = line[a];
    wait(0.0025);

  }
  }
}
else{
  break;
}
}
}
}
}