P9: A7,A13 battle ship 2016 J

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ColorMbed.cpp Source File

ColorMbed.cpp

00001 #include "mbed.h"
00002 #include "ColorMbed.h"
00003 
00004 SPI dot_matrix(D11,NC,D13); //mosi miso sclk
00005 DigitalOut lat(PA_12);
00006 DigitalOut sb(PA_11);
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 uint8_t temp;
00011 int line[8] = {1,2,4,8,16,32,64,128};
00012 
00013 
00014 
00015 void ColorMbed::init(){
00016   dot_matrix.frequency(1000000);
00017   uint8_t wb[3] = {255,255,255};
00018   rst = 1;
00019   wait(0.5);
00020   rst = 0;
00021   wait(0.5);
00022   rst = 1;
00023   wait(0.5);
00024   sb = 0; // 6 bit
00025   for(int i = 0; i<8; i++){
00026     dot_matrix.write(wb[0]);
00027     dot_matrix.write(wb[1]);
00028     dot_matrix.write(wb[2]);
00029   }
00030   open_line = 0;
00031   sb = 1; // 8 bit
00032 }
00033 
00034 
00035 void ColorMbed::display_pic(int *pic,int *color){
00036   for(int j = 0;j<8;j++){
00037     temp = pic[j];
00038     for(int i = 0; i<8; i++){
00039       if(temp & 0x80){
00040         dot_matrix.write(color[0]);
00041         dot_matrix.write(color[1]);
00042         dot_matrix.write(color[2]);
00043       }
00044       else{
00045         dot_matrix.write(0);
00046         dot_matrix.write(0);
00047         dot_matrix.write(0);
00048       }
00049       temp = temp << 1;
00050     }
00051     lat = 1;
00052     lat = 0;
00053     open_line = line[j];
00054     wait(0.001);
00055     open_line = 0;
00056   }
00057 }
00058 
00059 
00060 void ColorMbed::display_big_array(int pic[8][8][3]){
00061   for(int j = 0;j<8;j++){
00062     for(int i = 0; i<8; i++){
00063         dot_matrix.write(pic[j][7-i][0]);
00064         dot_matrix.write(pic[j][7-i][1]);
00065         dot_matrix.write(pic[j][7-i][2]);
00066     }
00067     lat = 1;
00068     lat = 0;
00069     open_line = line[j];
00070     wait(0.001);
00071     open_line = 0;
00072   }
00073 }