Aliexpressなどで販売されている64x32のフルカラードットマトリクスLED2枚とNucleo F401REを利用して、 E233系の駅停車時、路線名表示ありのLED側面行先表示を再現するプログラムです。 3秒間隔、3段階切替で、路線名、種別、行先、次停車駅を個別に指定することが可能です。
Dependencies: SDFileSystem mbed
Diff: main.cpp
- Revision:
- 13:0c542447e6da
- Parent:
- 12:680db9f1f4eb
- Child:
- 14:0f4d44927b20
--- a/main.cpp Wed Nov 12 17:24:45 2014 +0000 +++ b/main.cpp Thu Nov 13 16:29:36 2014 +0000 @@ -18,6 +18,8 @@ */ #include "mbed.h" +#include "SDFileSystem.h" + #define LOW 0 #define HIGH 1 @@ -40,10 +42,12 @@ #define LED_Width 128 #define LED_Height 16 -BusOut ABC(D8,D9,D10,D14); // Row address. -DigitalOut CLK(D11); // Data clock - rising edge -DigitalOut LAT(D12); // Data latch - active low (pulse up after data load) -DigitalOut OE(D13); // Output enable - active low (hold high during data load, bring low after LAT pulse) +SDFileSystem sd(D11, D12, D13, D10, "sd"); +Serial pc(USBTX,USBRX ); +BusOut ABC(D8,D9,PB_13,D14); // Row address. +DigitalOut CLK(PB_14); // Data clock - rising edge +DigitalOut LAT(PB_15); // Data latch - active low (pulse up after data load) +DigitalOut OE(PB_1); // Output enable - active low (hold high during data load, bring low after LAT pulse) DigitalOut R1(D6); // RED Serial in for upper half DigitalOut R2(D7); // RED Serial in for lower half DigitalOut G1(D2); // GREEN Serial in for upper half @@ -52,14 +56,40 @@ DigitalOut B2(D5); // BLUE Serial in for lower half +//SumSW +DigitalOut SCK(PB_7); +DigitalOut SI(PC_13); +DigitalOut RCK(PC_14); + +DigitalIn SumSW1(PA_0); +DigitalIn SumSW2(PA_1); +DigitalIn SumSW4(PA_4); +DigitalIn SumSW8(PB_0); + + + Ticker ChangeTimer; + + int ChangeCount = 0; +int LineNumber = 0; +int KindNumber = 0; +int ForNumber = 0; +int NextStaNumber = 0; + + + +//SDCardFilePath +char* SDFilePath = "/sd/a.txt"; + unsigned char gm[32][6]; // Buffer with 32x6 bytes. Graphics memory if you like. unsigned long CT; // Counter for demo code + + int LEDBuffer [32][128] = { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, @@ -414,9 +444,7 @@ OE = LOW; // Enable output wait_us(10); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. - } - - + } } @@ -434,33 +462,82 @@ void TimerTick(){ if (ChangeCount == 0){ + ChangeCount = ChangeCount + 1; + }else if(ChangeCount == 1 ){ + ChangeCount = ChangeCount + 1; + //ChangeCount = 0; + }else if(ChangeCount == 2){ + ChangeCount = 0; + }else{ + + } +} + + +int main() +{ + Init(); // Set things up + //Serial + pc.printf("Power ON\r\n"); + + //SumSW + SI = HIGH; + SCK = HIGH; + SI = LOW; + SCK = LOW; + + for(int a = 0; a < 14; a++){ + SCK = HIGH; + SCK = LOW; + } + + RCK = HIGH; + RCK = LOW; - ChangeCount = ChangeCount + 1; - }else if(ChangeCount == 1 ){ - + //SDCard + SDFilePath = "/sd/2.bin"; - ChangeCount = ChangeCount + 1; - //ChangeCount = 0; - }else if(ChangeCount == 2){ - - ChangeCount = 0; + FILE *fp = fopen(SDFilePath, "r"); + if(fp == NULL) { + pc.printf("SDFileOpen Error %s\r\n",SDFilePath); + //error("Could not open file for write\r\n"); }else{ - - + //fprintf(fp, "Hello fun SD Card World!"); + pc.printf("SDFileOpen Success %s\r\n",SDFilePath); + + //SDDataReadtest + //int Data; + //for(int y = 0; y < 32; y++){ + // for(int x = 0; x <112; x++){ + // Data = getc(fp); + // LEDBuffer[y][x] = Data; + // } + //} + fclose(fp); } - -} - -int main() -{ - Init(); // Set things up + //Debug + //DataSerialOut + for(int y = 0; y < 32; y++){ + for(int x = 0; x <128; x++){ + if(LEDBuffer[y][x]== 0){ + //pc.printf("0,"); + pc.printf(" "); + }else{ + //pc.printf("#"); + pc.printf("%.02d",LEDBuffer[y][x]); + } + } + pc.printf("\r\n"); + } + + //DisplayTimer ChangeTimer.attach(&TimerTick,3); - while(1) { // Messy demo loop following... + while(1) { CT++; if (ChangeCount == 0){ Paint(LEDBuffer); @@ -470,32 +547,6 @@ Paint(LEDBuffer3); } - //if((CT<=2560)||(CT>=2880 && CT<=4160)) { - // Paint(); // Refresh display - // if((CT % 20)==0) ShiftRight(); // After every 20 refresh, do a ShiftRight - //} - - //if(CT==2560) { - // for(int c=0; c<8; c++) { - // for(int x=c; x<(31-c); x++) {// Top side - // Pset(x,c,c); - // Paint(); // Display refresh time sets loop duration. - // } - // for(int y=c; y<(15-c); y++) {// Right side - // Pset(31-c,y,c); - // Paint(); - // } - // for(int x=(31-c); x>=c; x--) {// Bottom side - // Pset(x,(15-c),c); - // Paint(); - // } - // for(int y=(15-c); y>=c; y--) { // Left side - // Pset(c,y,c); - // Paint(); - // } - // } - //} - if(CT>4160) { //MkPattern(); // Restore original priceless artwork CT=0; // Start all over.