Aliexpressなどで販売されている64x32のフルカラードットマトリクスLED2枚とNucleo F401REを利用して、 E233系の駅停車時、路線名表示ありのLED側面行先表示を再現するプログラムです。 3秒間隔、3段階切替で、路線名、種別、行先、次停車駅を個別に指定することが可能です。
Dependencies: SDFileSystem mbed
Diff: main.cpp
- Revision:
- 29:bc82c25b6b94
- Parent:
- 28:4cc6aa3acd92
- Child:
- 30:3ac9aa4faa34
--- a/main.cpp Mon Feb 02 11:44:47 2015 +0000 +++ b/main.cpp Tue Feb 03 10:36:24 2015 +0000 @@ -44,10 +44,11 @@ #define B_Debug3 0 #define B_Debug4 0 - +//表示幅を増やす場合ここ以外も変更が必要 #define LED_Width 128 #define LED_Height 16 + #define DisplayWait 15 //最大停車駅数 @@ -65,6 +66,9 @@ Serial pc(USBTX,USBRX ); //LEDModule +//R1,R2,G1,G2,B1,B2はモジュールによりコネクタのピンアサインが異なります。 +//色が違う場合DigitalOutのピンアサインを変更してください。 + //R1 - D4(PB5) //R2 - D5(PB4) //G1 - D6(PB10) @@ -97,7 +101,7 @@ -//SumSW +//SumSW(現状未使用) DigitalOut SCK(PB_7); DigitalOut SI(PC_13); DigitalOut RCK(PC_14); @@ -106,10 +110,12 @@ DigitalIn SumSW2(PA_1); DigitalIn SumSW4(PA_4); DigitalIn SumSW8(PB_0); - //BusIn SumSWNum(PA_0,PA_1,PA_4,PB_0); + +//表示切替用タイマ Ticker ChangeTimer; +//スクロール用タイマ(現状未使用) Ticker ScrollTimer; //Debug @@ -135,6 +141,7 @@ bool Scroll = 1; //起動時スクロール読み込み有効/無効(SDがない場合0にする) +//(1になっている場合SDカードが刺さっていないと起動に数分かかります) bool ScrollEnable = 1; int ChangeCount = 0; @@ -154,9 +161,16 @@ //SDCardFilePath char SDFilePath[80]= "/sd/a.txt"; -unsigned char gm[32][6]; // Buffer with 32x6 bytes. Graphics memory if you like. +//unsigned char gm[32][6]; // Buffer with 32x6 bytes. Graphics memory if you like. unsigned long CT; // Counter for demo code + +//StopStationCode:停車駅コード(最大100駅 それ以上の場合MaxStopStationを増やしてください) +//停車駅コード終端は0にする +//StationNameLength:駅名の文字数(最大8文字) +//停車駅名データ:/sd/E233/StationName/(停車駅コード).bin +//128x32 + //int StopStationCode[MaxStopStation] = {2,3,7,11,14,20,24,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,0}; //Keihin-Tohoku Rapid Ofuna //int StopStationCode[MaxStopStation] = {202,203,204,205,206,207,208,209,210,211,212,213,214,218,220,222,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,0}; @@ -382,16 +396,16 @@ } -void WriteRow(unsigned char Row, int8_t Buffer[32][128], int8_t index) +void WriteRow(unsigned char Row, int8_t Buffer[32][128], int8_t index2) { ABC = 15-Row; for(int col=0; col<LED_Width; col++) { - R1 = R1Data[index][(Buffer [(15-Row)][col])]; - G1 = G1Data[index][(Buffer [(15-Row)][col])]; - B1 = B1Data[index][(Buffer [(15-Row)][col])]; - R2 = R1Data[index][(Buffer [(31-Row)][col])]; - G2 = G1Data[index][(Buffer [(31-Row)][col])]; - B2 = B1Data[index][(Buffer [(31-Row)][col])]; + R1 = R1Data[index2][(Buffer [(15-Row)][col])]; + G1 = G1Data[index2][(Buffer [(15-Row)][col])]; + B1 = B1Data[index2][(Buffer [(15-Row)][col])]; + R2 = R1Data[index2][(Buffer [(31-Row)][col])]; + G2 = G1Data[index2][(Buffer [(31-Row)][col])]; + B2 = B1Data[index2][(Buffer [(31-Row)][col])]; CLK = HIGH; CLK = LOW; } @@ -417,21 +431,21 @@ LAT = LOW; } -void Pset(unsigned char x,unsigned char y, unsigned char c) -{ +//void Pset(unsigned char x,unsigned char y, unsigned char c) +//{ // Set pixel (x,y) to color c // Manipulates graphics memory, so you won't see any change til you Paint() it. - unsigned char ud,l,r0,g0,b0; - ud=(y & 8)>>3; // 0 = upper half, 1 = lower half - l=y & 7; // Extract row in upper/lower half - r0=(c & 4) >>2; // Extract red bit from color - g0=(c & 2) >>1; // Extract green bit from color - b0=(c & 1); // Extract blue bit from color +// unsigned char ud,l,r0,g0,b0; +// ud=(y & 8)>>3; // 0 = upper half, 1 = lower half +// l=y & 7; // Extract row in upper/lower half +// r0=(c & 4) >>2; // Extract red bit from color +// g0=(c & 2) >>1; // Extract green bit from color +// b0=(c & 1); // Extract blue bit from color // *******Removes current bit ******* *Adds bit** - gm[x][0+3*ud]=(gm[x][0+3*ud] & (255-(1<<(7-l))))+(r0<<(7-l)); // Red byte - gm[x][1+3*ud]=(gm[x][1+3*ud] & (255-(1<<(7-l))))+(g0<<(7-l)); // Green byte - gm[x][2+3*ud]=(gm[x][2+3*ud] & (255-(1<<(7-l))))+(b0<<(7-l)); // Blue byte -} +// gm[x][0+3*ud]=(gm[x][0+3*ud] & (255-(1<<(7-l))))+(r0<<(7-l)); // Red byte +// gm[x][1+3*ud]=(gm[x][1+3*ud] & (255-(1<<(7-l))))+(g0<<(7-l)); // Green byte +// gm[x][2+3*ud]=(gm[x][2+3*ud] & (255-(1<<(7-l))))+(b0<<(7-l)); // Blue byte +//} void Paint(int8_t Buffer2[32][128]) { @@ -439,9 +453,10 @@ for(int Row=0; Row<LED_Height; Row++) { OE = HIGH; // Disable output WriteRow(Row,Buffer2,index); - //wait_us(10); + //wait_us(5); OE = LOW; // Enable output wait_us(DisplayWait); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. + OE = HIGH; // Disable output } } } @@ -473,25 +488,15 @@ } void CopyScrollBuffer(int8_t ReadBuffer[16][2048],int8_t WriteBuffer[32][128],int Startx){ - - - for(int y = 0; y < 16; y++){ - int xCount = 0; - + int xCount = 0; for(int x = 0; x < 80; x++){ - //for(int z =0; z < 8; z++){ - //LEDMainBuffer[y + 16][x + 48] = ScrollBuffer[y][x + Startx]; - if(bitRead(ScrollBuffer[y][(x + Startx) / 8 ], (x + Startx)% 8) != 0){ LEDMainBuffer[y + 16][x + 48] = 4; }else{ LEDMainBuffer[y + 16][x + 48] = 0; - } - + } xCount = xCount + 1; - //} - } } } @@ -509,7 +514,6 @@ void TimerTick(){ //OE = HIGH; - //DisplayMode = 1 3段階表示ならば if(DisplayMode == 1){ if (ChangeCount == 0){ @@ -967,47 +971,47 @@ //SumSW - int testData[16] = {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0}; - SI = LOW; - for(int a = 0; a < 16; a++){ - if(testData[a] == 1){ - SI = HIGH; - pc.printf("1,"); - }else{ - SI = LOW; - pc.printf("0,"); - } - SCK = HIGH; - wait_us(15); - SCK = LOW; - wait_us(15); - } + //int testData[16] = {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0}; + //SI = LOW; + //for(int a = 0; a < 16; a++){ + // if(testData[a] == 1){ + // SI = HIGH; + // pc.printf("1,"); + // }else{ + // SI = LOW; + // pc.printf("0,"); + // } + // SCK = HIGH; + // wait_us(15); + // SCK = LOW; + // wait_us(15); + //} - RCK = HIGH; - wait_us(15); - RCK = LOW; - pc.printf("\r\n"); + //RCK = HIGH; + //wait_us(15); + //RCK = LOW; + //pc.printf("\r\n"); - int SumSWNum = 0; - if(SumSW1 == 1 ){ - SumSWNum = SumSWNum + 1; - } - if(SumSW2 == 1){ - SumSWNum = SumSWNum + 2; - } - if(SumSW4 == 1){ - SumSWNum = SumSWNum + 4; - } - if(SumSW8 == 1){ - SumSWNum = SumSWNum + 8; - } - pc.printf("SumSW:%d\r\n",SumSWNum); + //int SumSWNum = 0; + //if(SumSW1 == 1 ){ + // SumSWNum = SumSWNum + 1; + //} + //if(SumSW2 == 1){ + // SumSWNum = SumSWNum + 2; + //} + //if(SumSW4 == 1){ + // SumSWNum = SumSWNum + 4; + //} + //if(SumSW8 == 1){ + // SumSWNum = SumSWNum + 8; + //} + //pc.printf("SumSW:%d\r\n",SumSWNum); - + //SDカードから表示データを読み込み SDFileRead(); - + //起動時にスクロールデータを読み込み if(ScrollEnable == 1){ //ScrollDebug ScrollWriteCount = 80; @@ -1024,7 +1028,6 @@ if(StopStationCode[i] == 0){ break; } - //駅名 sprintf(SDFilePath,"/sd/E233/StationName/%d.bin",StopStationCode[i]); SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,128,16); @@ -1047,10 +1050,7 @@ sprintf(SDFilePath,"/sd/E233/StopStation/0x8132.bin"); SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,16,16); ScrollWriteCount = ScrollWriteCount + 16; - } - - ScrollWriteCount = ScrollWriteCount - 16; sprintf(SDFilePath,"/sd/E233/StopStation/StopStation%d.bin",3); SDScrollBufferWrite(ScrollBuffer,ScrollWriteCount,0,80,16); @@ -1085,10 +1085,6 @@ //2段階表示に変更 DisplayMode = 2; - - - - //Serial pc.attach(pc_rx, Serial::RxIrq); @@ -1103,7 +1099,7 @@ while(1) { - CT++; + //CT++; // if (ChangeCount == 0){ // Paint(LEDBuffer); // }else if(ChangeCount == 1){ @@ -1117,17 +1113,17 @@ //スクロール(現状不動作) //スクロールが有効なら if(Scroll == 1){ - if(CT>0) { + //if(CT>0) { //MkPattern(); // Restore original priceless artwork - CT=0; // Start all over. + //CT=0; // Start all over. OE = HIGH; ScrollTimerTick(); OE = LOW; - } - }else{ - if(CT>4160){ - CT=0; - } + //} + //}else{ + //if(CT>4160){ + // CT=0; + //} }