Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LEDMatrix_Master by
main.cpp
00001 #pragma import __use_all_ctype 00002 00003 #include "mbed.h" 00004 #include <string.h> 00005 #include "displayCom.h" 00006 #include "kfont8.h" 00007 #include "8x8fontsLib.h" 00008 #include "15x16fontsLib.h" 00009 00010 SPI spi(p5, p6, p7); //mosi, miso, sclk 00011 BusOut buffer_CS(p15,p16,p17,p18,p19,p20); 00012 Serial pc(USBTX, USBRX); // tx, rx 00013 LocalFileSystem local("local"); 00014 00015 unsigned int ImageBuf[3][DISPLAY_XSIZE];//16*6 00016 unsigned int ColerMap[3][DISPLAY_XSIZE]; 00017 00018 unsigned int CountChar_full_W(char *str ) 00019 { 00020 unsigned char f_SJISChar = 0; 00021 unsigned char c = 0; 00022 unsigned int CountChar = 0; 00023 00024 c = *str; 00025 while(c != '\0') 00026 { 00027 //2バイト文字の判定 00028 if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && f_SJISChar != 1 ) 00029 { 00030 f_SJISChar = 1; 00031 } 00032 else if(f_SJISChar == 1) 00033 { 00034 CountChar++; 00035 f_SJISChar = 0; 00036 } 00037 else 00038 { 00039 f_SJISChar = 0; 00040 } 00041 00042 str++; 00043 c = *str; 00044 } 00045 return CountChar; 00046 } 00047 00048 unsigned int CountChar_half_W(char *str) 00049 { 00050 unsigned char f_SJISChar = 0; 00051 unsigned char c = 0; 00052 unsigned int CountChar = 0; 00053 00054 c = *str; 00055 while(c != '\0') 00056 { 00057 //2バイト文字の判定 00058 if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && f_SJISChar != 1 ) 00059 { 00060 f_SJISChar = 1; 00061 } 00062 else 00063 { 00064 if( f_SJISChar == 1) 00065 { 00066 f_SJISChar = 0; 00067 } 00068 else 00069 { 00070 CountChar++; 00071 } 00072 } 00073 str++; 00074 c = *str; 00075 } 00076 return CountChar; 00077 } 00078 void SPILineOut(unsigned char setLine) 00079 { 00080 unsigned int data[3]={0}; 00081 unsigned int i = 0; 00082 for(i=0;i<=5;i++) 00083 { 00084 data[0] |= ((ImageBuf[2][setLine]>>(15-i))&0x01) << (15-(3*i)); 00085 } 00086 for(i=0;i<=4;i++) 00087 { 00088 data[0] |= ((ImageBuf[1][setLine]>>(15-i))&0x01) << (14-(3*i)); 00089 data[0] |= ((ImageBuf[0][setLine]>>(15-i))&0x01) << (13-(3*i)); 00090 } 00091 00092 for(i=0;i<=5;i++) 00093 { 00094 data[1] |= ((ImageBuf[1][setLine]>>(10-i))&0x01) << (15-(3*i)); 00095 } 00096 for(i=0;i<=4;i++) 00097 { 00098 data[1] |= ((ImageBuf[0][setLine]>>(10-i))&0x01) << (14-(3*i)); 00099 data[1] |= ((ImageBuf[2][setLine]>>(9-i))&0x01) << (13-(3*i)); 00100 } 00101 00102 for(i=0;i<=5;i++) 00103 { 00104 data[2] |= ((ImageBuf[0][setLine]>>(5-i))&0x01) << (15-(3*i)); 00105 } 00106 for(i=0;i<=4;i++) 00107 { 00108 data[2] |= ((ImageBuf[2][setLine]>>(4-i))&0x01) << (14-(3*i)); 00109 data[2] |= ((ImageBuf[1][setLine]>>(4-i))&0x01) << (13-(3*i)); 00110 } 00111 spi.write(data[0]); 00112 spi.write(data[1]); 00113 spi.write(data[2]); 00114 } 00115 00116 void outBordData() 00117 { 00118 unsigned char ch = 0,Max_ch=0; 00119 unsigned int i = 0; 00120 Max_ch = (DISPLAY_XSIZE-16)/16; 00121 for(ch=0;ch<=Max_ch;ch++) 00122 { 00123 wait_us(10); 00124 buffer_CS = 0x01 << ch; 00125 for(i=(ch*16);i<(ch*16+16);i++) 00126 { 00127 SPILineOut(i); 00128 } 00129 } 00130 } 00131 00132 void bufLeftShift_Loop(void) 00133 { 00134 signed int i = 0; 00135 00136 for(i=(DISPLAY_XSIZE-1);i>=1;i--) 00137 { 00138 ImageBuf[0][i] = ImageBuf[0][i-1]; 00139 ImageBuf[1][i] = ImageBuf[1][i-1]; 00140 ImageBuf[2][i] = ImageBuf[2][i-1]; 00141 } 00142 ImageBuf[0][0] = ImageBuf[0][(DISPLAY_XSIZE-1)]; 00143 ImageBuf[1][0] = ImageBuf[1][(DISPLAY_XSIZE-1)]; 00144 ImageBuf[2][0] = ImageBuf[2][(DISPLAY_XSIZE-1)]; 00145 00146 } 00147 00148 void bufLeftShift(void) 00149 { 00150 signed int i = 0; 00151 00152 for(i=(DISPLAY_XSIZE-1);i>=1;i--) 00153 { 00154 ImageBuf[0][i] = ImageBuf[0][i-1]; 00155 ImageBuf[1][i] = ImageBuf[1][i-1]; 00156 ImageBuf[2][i] = ImageBuf[2][i-1]; 00157 } 00158 ImageBuf[0][0] = 0; 00159 ImageBuf[1][0] = 0; 00160 ImageBuf[2][0] = 0; 00161 } 00162 00163 void TestMode(void) 00164 { 00165 unsigned char i = 0; 00166 00167 for(i=0;i<16;i++) 00168 { 00169 ImageBuf[0][i] = 0xffff; 00170 } 00171 for(i=16;i<16+16;i++) 00172 { 00173 ImageBuf[1][i] = 0xffff; 00174 } 00175 for(i=32;i<32+16;i++) 00176 { 00177 ImageBuf[2][i] = 0xffff; 00178 } 00179 00180 outBordData(); 00181 00182 while(1) 00183 { 00184 wait(0.1); 00185 bufLeftShift_Loop(); 00186 outBordData(); 00187 } 00188 } 00189 00190 void SetRandamColer(void) 00191 { 00192 unsigned char color = 0; 00193 unsigned int i=0,j=0; 00194 00195 memset(ColerMap,0,sizeof(ColerMap)); 00196 for(j=0;j<DISPLAY_XSIZE;j++) 00197 { 00198 for(i=0;i<16;i++) 00199 { 00200 color = rand()%7; 00201 if(color == COLOR_G || color == COLOR_C || color == COLOR_Y || color == COLOR_W) 00202 { 00203 ColerMap[0][j] |= 1<<i; 00204 } 00205 if(color == COLOR_R || color == COLOR_Y || color == COLOR_M || color == COLOR_W) 00206 { 00207 ColerMap[1][j] |= 1<<i; 00208 } 00209 if(color == COLOR_B || color == COLOR_C || color == COLOR_M || color == COLOR_W) 00210 { 00211 ColerMap[2][j] |= 1<<i; 00212 } 00213 } 00214 } 00215 } 00216 00217 void ApplyColerMap(void) 00218 { 00219 unsigned i = 0; 00220 for(i=0;i<DISPLAY_XSIZE;i++) 00221 { 00222 ImageBuf[0][i] = ImageBuf[0][i]&ColerMap[0][i]; 00223 ImageBuf[1][i] = ImageBuf[1][i]&ColerMap[1][i]; 00224 ImageBuf[2][i] = ImageBuf[2][i]&ColerMap[2][i]; 00225 } 00226 } 00227 00228 int main() 00229 { 00230 unsigned int i = 0; 00231 unsigned int s_Strs = 0; 00232 00233 char strs[100]={}; 00234 memset(strs,' ',sizeof(strs)); 00235 // Read text file for display message, if exist. 00236 FILE *fp; 00237 fp = fopen("/local/message.txt", "r"); 00238 if (fp != NULL) { 00239 fgets(strs, 100, fp); 00240 fclose(fp); 00241 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler 00242 free(fp); 00243 #endif 00244 } 00245 spi.format(16,1); 00246 spi.frequency(1000000); 00247 00248 memset(ImageBuf,0,sizeof(ImageBuf)); 00249 00250 i=0; 00251 wait(0.2); 00252 //TestMode(); 00253 SetRandamColer(); 00254 00255 while(1) 00256 { 00257 memset(ImageBuf,0,sizeof(ImageBuf)); 00258 s_Strs = CountChar_half_W(strs)*8; 00259 s_Strs += CountChar_full_W(strs)*16; 00260 for(i=0; i<DISPLAY_XSIZE+(s_Strs)-16; i++) 00261 { 00262 #if 1 00263 drawStr15x16(strs ,i, COLOR_W); 00264 ApplyColerMap(); 00265 #else 00266 drawStr15x16_AutoColer(strs ,i); 00267 #endif 00268 outBordData(); 00269 wait(0.05); 00270 } 00271 } 00272 }
Generated on Tue Jul 12 2022 16:59:14 by
1.7.2
