Aliexpressなどで販売されている64x32のフルカラードットマトリクスLED2枚とNucleo F401REを利用して、 E233系の駅停車時、路線名表示ありのLED側面行先表示を再現するプログラムです。 3秒間隔、3段階切替で、路線名、種別、行先、次停車駅を個別に指定することが可能です。
Dependencies: SDFileSystem mbed
Diff: main.cpp
- Revision:
- 4:245f17936b1a
- Parent:
- 3:6dbbc0130e96
- Child:
- 5:532937f20397
diff -r 6dbbc0130e96 -r 245f17936b1a main.cpp --- a/main.cpp Sun Oct 19 11:16:58 2014 +0000 +++ b/main.cpp Sun Oct 19 16:20:02 2014 +0000 @@ -35,6 +35,27 @@ unsigned char gm[32][6]; // Buffer with 32x6 bytes. Graphics memory if you like. unsigned long CT; // Counter for demo code +const int LEDBuffer [16][32] = { + {0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,2,0,0}, + {0,0,0,2,0,0,2,0,0,2,2,2,2,0,2,2,2,0,0,0,2,0,0,2,0,0,0,0,0,2,0,0}, + {0,0,2,2,2,2,2,0,0,2,0,2,0,0,2,0,2,0,0,0,2,2,2,2,2,2,0,2,2,2,2,2}, + {0,0,2,0,0,0,2,0,0,2,0,2,0,0,2,0,2,0,0,0,2,0,0,0,0,0,0,0,0,2,0,0}, + {0,2,2,0,0,0,2,0,0,2,2,2,2,0,2,0,2,0,0,2,0,0,2,2,2,0,0,2,2,2,2,2}, + {0,0,0,2,0,2,0,0,0,2,0,2,0,0,2,0,2,0,0,2,0,0,2,0,2,0,0,2,0,2,0,2}, + {0,0,0,0,2,0,0,0,0,2,0,2,0,0,2,2,2,0,2,2,0,0,2,2,2,0,0,2,0,2,0,2}, + {0,0,0,2,2,0,0,0,0,2,2,2,2,0,2,2,0,0,0,2,0,0,0,0,0,0,0,2,2,2,2,2}, + {0,0,2,0,0,2,0,0,0,2,0,2,0,0,2,2,0,0,0,2,0,2,2,2,2,2,0,2,0,2,0,2}, + {0,2,0,0,0,0,2,0,0,2,0,2,0,0,2,2,0,0,0,2,0,2,0,0,0,2,0,2,0,2,0,2}, + {2,2,2,2,2,2,2,2,0,2,2,2,2,0,2,2,0,0,0,2,0,0,0,0,0,0,0,2,2,2,2,2}, + {0,2,0,0,0,0,2,0,0,0,0,0,2,0,2,0,2,0,0,2,0,0,2,2,2,0,0,0,0,2,0,0}, + {0,2,0,0,0,0,2,0,0,0,0,0,2,0,2,0,2,0,0,2,0,0,0,2,0,0,2,2,2,2,2,2}, + {0,2,0,0,0,0,2,0,2,2,2,0,2,0,2,0,2,0,0,2,0,0,0,2,0,0,0,0,0,2,0,0}, + {0,2,2,2,2,2,2,0,0,0,0,0,2,0,2,0,2,0,0,2,0,0,0,2,0,0,0,0,0,2,0,0}, + {0,2,0,0,0,0,2,0,0,0,0,2,2,0,2,0,2,0,0,2,0,0,2,2,0,0,0,0,0,2,0,0} + }; + + + void MkPattern() // Fill graphics buffer with colorful test pattern. { unsigned int col,r,g,b; @@ -97,12 +118,80 @@ // Write specified row (and row+8) to display. Valid input: 0 to 7. ABC = 7-Row; // Set row address for(int col=0; col<32; col++) { // To daisychain more displays, I guess you would have to increase this counter to n*32 columns. Might mirror though. - R1 = gm[col][0] & (1<<Row); // Red bit, upper half - G1 = gm[col][1] & (1<<Row); // Green bit, upper half - B1 = gm[col][2] & (1<<Row); // Blue bit, upper half - R2 = gm[col][3] & (1<<Row); // Red bit, lower half - G2 = gm[col][4] & (1<<Row); // Green bit, lower half - B2 = gm[col][5] & (1<<Row); // Blue bit, lower half + //R1 = gm[col][0] & (1<<Row); // Red bit, upper half + //G1 = gm[col][1] & (1<<Row); // Green bit, upper half + //B1 = gm[col][2] & (1<<Row); // Blue bit, upper half + //R2 = gm[col][3] & (1<<Row); // Red bit, lower half + //G2 = gm[col][4] & (1<<Row); // Green bit, lower half + //B2 = gm[col][5] & (1<<Row); // Blue bit, lower half + + + if (LEDBuffer [(7-Row)][col] == 2){ + R1 = 1; + G1 = 1; + B1 = 0; + }else{ + R1 = 0; + G1 = 0; + B1 = 0; + } + + if (LEDBuffer [(15-Row)][col] == 2){ + R2 = 1; + G2 = 0; + B2 = 0; + }else{ + R2 = 0; + G2 = 0; + B2 = 0; + } + + + + + CLK = HIGH; // tick (clock bit in) + CLK = LOW; // tock + } + LAT = HIGH; // Latch entire row + LAT = LOW; +} + +void WrRow2(unsigned char Row) +{ + // Write specified row (and row+8) to display. Valid input: 0 to 7. + ABC = 7-Row; // Set row address + for(int col=0; col<32; col++) { // To daisychain more displays, I guess you would have to increase this counter to n*32 columns. Might mirror though. + //R1 = gm[col][0] & (1<<Row); // Red bit, upper half + //G1 = gm[col][1] & (1<<Row); // Green bit, upper half + //B1 = gm[col][2] & (1<<Row); // Blue bit, upper half + //R2 = gm[col][3] & (1<<Row); // Red bit, lower half + //G2 = gm[col][4] & (1<<Row); // Green bit, lower half + //B2 = gm[col][5] & (1<<Row); // Blue bit, lower half + + + if (LEDBuffer [(7-Row)][col] == 2){ + R1 = 1; + G1 = 1; + B1 = 1; + }else{ + R1 = 0; + G1 = 0; + B1 = 0; + } + + if (LEDBuffer [(15-Row)][col] == 2){ + R2 = 1; + G2 = 0; + B2 = 1; + }else{ + R2 = 0; + G2 = 0; + B2 = 0; + } + + + + CLK = HIGH; // tick (clock bit in) CLK = LOW; // tock } @@ -150,8 +239,29 @@ for(int Row=0; Row<8; Row++) { OE = HIGH; // Disable output WrRow(Row); + //WrRow2(Row); OE = LOW; // Enable output - wait_us(500); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. + + wait_us(25); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. + } + + + + + + +} + +void Paint2() +{ + // Write graphics memory to display + for(int Row=0; Row<8; Row++) { + OE = HIGH; // Disable output + //WrRow(Row); + WrRow2(Row); + OE = LOW; // Enable output + + wait_us(25); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. } } @@ -163,7 +273,7 @@ OE = HIGH; // Disable output WrRowOFF(Row); OE = LOW; // Enable output - wait_us(500); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. + wait_us(50); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh. } } @@ -175,39 +285,42 @@ while(1) { // Messy demo loop following... CT++; - if((CT<=2560)||(CT>=2880 && CT<=4160)) { - Paint(); // Refresh display - if((CT % 20)==0) ShiftRight(); // After every 20 refresh, do a ShiftRight - } + Paint(); // Refresh display + Paint2(); // Refresh display + + //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==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 + //MkPattern(); // Restore original priceless artwork CT=0; // Start all over. } - PaintOFF(); - wait_us(100); + //PaintOFF(); + //wait_us(160); } }