11/12/2560
Dependencies: mbed
Fork of ColorMbed by
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(PB_12); 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 uint8_t position[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; 00012 int line[8] = {1,2,4,8,16,32,64,128}; 00013 00014 void ColorMbed::init(){ 00015 dot_matrix.frequency(1000000); 00016 uint8_t wb[3] = {255,255,255}; 00017 rst = 1; 00018 wait(0.5); 00019 rst = 0; 00020 wait(0.5); 00021 rst = 1; 00022 wait(0.5); 00023 sb = 0; // 6 bit 00024 for(int i = 0; i<8; i++){ 00025 dot_matrix.write(wb[0]); 00026 dot_matrix.write(wb[1]); 00027 dot_matrix.write(wb[2]); 00028 } 00029 open_line = 0; 00030 sb = 1; // 8 bit 00031 } 00032 00033 // *********************** configur later ********************************* 00034 void ColorMbed::display_dot(int row,int col ,uint8_t *color){ 00035 //for(int j = 0; j<8;j++){ 00036 temp = position[col]; 00037 for(int i = 0 ; i< 8 ; i++){ 00038 if(temp & 0x80){ 00039 dot_matrix.write(color[0]); 00040 dot_matrix.write(color[1]); 00041 dot_matrix.write(color[2]); 00042 } 00043 else{ 00044 dot_matrix.write(0); 00045 dot_matrix.write(0); 00046 dot_matrix.write(0); 00047 } 00048 temp = temp << 1; 00049 } 00050 lat = 1; 00051 lat = 0; 00052 open_line = line[row]; 00053 00054 open_line = 0; 00055 00056 //} 00057 } 00058 00059 // void ColorMbed::display_ship(int row,int column,int type,uint8_t *color){ 00060 // if(type == 1){ 00061 // 00062 // } 00063 // else if(type == 2){ 00064 // 00065 // } 00066 // } 00067 00068 void ColorMbed::display_pic(uint8_t *pic,uint8_t *color){ 00069 for(int j = 0;j<8;j++){ 00070 temp = pic[j]; 00071 for(int i = 0; i<8; i++){ 00072 if(temp & 0x80){ 00073 dot_matrix.write(color[0]); 00074 dot_matrix.write(color[1]); 00075 dot_matrix.write(color[2]); 00076 } 00077 else{ 00078 dot_matrix.write(0); 00079 dot_matrix.write(0); 00080 dot_matrix.write(0); 00081 } 00082 temp = temp << 1; 00083 } 00084 lat = 1; 00085 lat = 0; 00086 open_line = line[j]; 00087 wait(0.001); 00088 open_line = 0; 00089 } 00090 } 00091 00092 // *********************** private function ********************************* 00093 00094 00095 int ColorMbed::_power(int number , int power){ 00096 int i = 0; 00097 int number1 = number; 00098 if(power == 0){return 1;} 00099 for(i = 1 ; i <= power ; i++ ){ 00100 if(power == 1){return number;} 00101 if(i == 1){number = number * 1;} 00102 else{number1 = number1 * number;} 00103 } 00104 return number1; 00105 }
Generated on Tue Jul 12 2022 18:44:48 by
1.7.2
