Aliexpressなどで販売されている64x32のフルカラードットマトリクスLED2枚とNucleo F401REを利用して、 E233系の駅停車時、路線名表示ありのLED側面行先表示を再現するプログラムです。 3秒間隔、3段階切替で、路線名、種別、行先、次停車駅を個別に指定することが可能です。

Dependencies:   SDFileSystem mbed

Committer:
RRacer
Date:
Mon Nov 19 02:16:13 2012 +0000
Revision:
1:dd0dcd303d6d
Parent:
0:1f58ecec51d6
Child:
2:c1a9a2a0885d
Public

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RRacer 0:1f58ecec51d6 1 /*
RRacer 0:1f58ecec51d6 2 The goal of this program is to show the basic connections and workings of Adafruits 32x16 RGB LED matrix board (http://www.adafruit.com/products/420),
RRacer 0:1f58ecec51d6 3 also sold on other places, for instance http://www.ebay.com/itm/PH6-RGB-Full-Color-LED-16-32-Dot-Matrix-Display-Module-/310303408628?pt=LH_DefaultDomain_0&hash=item483f8641f4 (no
RRacer 0:1f58ecec51d6 4 affiliation with either of them).
RRacer 0:1f58ecec51d6 5 This program is not intended to be highly optimized or a guideline in C programming in any way (more of the opposite actually).
RRacer 1:dd0dcd303d6d 6 To have more than 7 colors on this thing, you need to implement software PWM of some sort. I have obviously not done that, but if YOU do, please let me know!
RRacer 1:dd0dcd303d6d 7 Adafruit have a wicked demo program for an arduino - www.youtube.com/watch?v=lY-flFEfsHo
RRacer 0:1f58ecec51d6 8 There are probably lots of ways to make this perform better, perhaps by using Neal Hormans port of the Adafruit_GFX library (http://mbed.org/users/nkhorman/code/Adafruit_GFX/).
RRacer 0:1f58ecec51d6 9 No error checking or out-of-bounds checking is done. Use at your own peril.
RRacer 0:1f58ecec51d6 10 For more detailed information on the driver chip, see http://www.bjtopspace.com/ziliao/CYT62726.pdf
RRacer 0:1f58ecec51d6 11 Although the chips on my board says jx15020, I've been informed that they are equvivalent to the CYT62726, and so far it's a match.
RRacer 0:1f58ecec51d6 12 Feel free to use all or parts of this work.
RRacer 0:1f58ecec51d6 13 If you choose to do so, I would appreciate a small mentioning in the scrolling opening credits ;)
RRacer 0:1f58ecec51d6 14
RRacer 0:1f58ecec51d6 15 Best regards,
RRacer 0:1f58ecec51d6 16 Hugo Harming
RRacer 0:1f58ecec51d6 17 upgraded@hotmail.com
RRacer 0:1f58ecec51d6 18 */
RRacer 0:1f58ecec51d6 19
RRacer 0:1f58ecec51d6 20 #include "mbed.h"
RRacer 0:1f58ecec51d6 21 #define LOW 0
RRacer 0:1f58ecec51d6 22 #define HIGH 1
RRacer 0:1f58ecec51d6 23
RRacer 0:1f58ecec51d6 24 BusOut ABC(p24,p25,p26); // Row address.
RRacer 0:1f58ecec51d6 25 DigitalOut CLK(p21); // Data clock - rising edge
RRacer 0:1f58ecec51d6 26 DigitalOut LAT(p22); // Data latch - active low (pulse up after data load)
RRacer 0:1f58ecec51d6 27 DigitalOut OE(p23); // Output enable - active low (hold high during data load, bring low after LAT pulse)
RRacer 0:1f58ecec51d6 28 DigitalOut R1(p27); // RED Serial in for upper half
RRacer 0:1f58ecec51d6 29 DigitalOut R2(p28); // RED Serial in for lower half
RRacer 0:1f58ecec51d6 30 DigitalOut G1(p5); // GREEN Serial in for upper half
RRacer 0:1f58ecec51d6 31 DigitalOut G2(p6); // GREEN Serial in for lower half
RRacer 0:1f58ecec51d6 32 DigitalOut B1(p7); // BLUE Serial in for upper half
RRacer 0:1f58ecec51d6 33 DigitalOut B2(p8); // BLUE Serial in for lower half
RRacer 0:1f58ecec51d6 34
RRacer 0:1f58ecec51d6 35 unsigned char gm[32][6]; // Buffer with 32x6 bytes. Graphics memory if you like.
RRacer 0:1f58ecec51d6 36 unsigned long CT; // Counter for demo code
RRacer 0:1f58ecec51d6 37
RRacer 0:1f58ecec51d6 38 void MkPattern() // Fill graphics buffer with colorful test pattern.
RRacer 0:1f58ecec51d6 39 {
RRacer 0:1f58ecec51d6 40 unsigned int col,r,g,b;
RRacer 0:1f58ecec51d6 41 r=0x0f0f0f0f;
RRacer 0:1f58ecec51d6 42 g=0x33333333;
RRacer 0:1f58ecec51d6 43 b=0x55555555;
RRacer 0:1f58ecec51d6 44 for(col=0; col<32; col++) {
RRacer 0:1f58ecec51d6 45 gm[col][0]=(r>>(col % 8)) & 0xff; // Shift red value and mask out LSB.
RRacer 0:1f58ecec51d6 46 gm[col][1]=(g>>(col % 8)) & 0xff; // Shift green value and mask out LSB.
RRacer 0:1f58ecec51d6 47 gm[col][2]=(b>>(col % 8)) & 0xff; // Shift blue value and mask out LSB.
RRacer 0:1f58ecec51d6 48 gm[col][3]=gm[col][0]; // Copy top red byte to bottom red byte.
RRacer 0:1f58ecec51d6 49 gm[col][4]=gm[col][1]; // Copy top green byte to bottom green byte.
RRacer 0:1f58ecec51d6 50 gm[col][5]=gm[col][2]; // Copy top blue byte to bottom blue byte.
RRacer 0:1f58ecec51d6 51 }
RRacer 0:1f58ecec51d6 52 }
RRacer 0:1f58ecec51d6 53
RRacer 0:1f58ecec51d6 54 void Init()
RRacer 0:1f58ecec51d6 55 {
RRacer 0:1f58ecec51d6 56 // Set up things to a known state
RRacer 0:1f58ecec51d6 57 CLK = LOW;
RRacer 0:1f58ecec51d6 58 LAT = LOW;
RRacer 0:1f58ecec51d6 59 OE = HIGH; //display off
RRacer 0:1f58ecec51d6 60 ABC = 0;
RRacer 0:1f58ecec51d6 61 CT=0;
RRacer 0:1f58ecec51d6 62 MkPattern();
RRacer 0:1f58ecec51d6 63 }
RRacer 0:1f58ecec51d6 64
RRacer 0:1f58ecec51d6 65 void ShiftRight()
RRacer 0:1f58ecec51d6 66 {
RRacer 0:1f58ecec51d6 67 unsigned char i,r,g,b;
RRacer 0:1f58ecec51d6 68 r=gm[31][0]; // Save value of last column (top half)
RRacer 0:1f58ecec51d6 69 g=gm[31][1];
RRacer 0:1f58ecec51d6 70 b=gm[31][2];
RRacer 0:1f58ecec51d6 71
RRacer 0:1f58ecec51d6 72 for(i=31; i>0; i--) { // Copy value of column n to column n-1
RRacer 0:1f58ecec51d6 73 gm[i][0]=gm[i-1][0];
RRacer 0:1f58ecec51d6 74 gm[i][1]=gm[i-1][1];
RRacer 0:1f58ecec51d6 75 gm[i][2]=gm[i-1][2];
RRacer 0:1f58ecec51d6 76 }
RRacer 0:1f58ecec51d6 77 gm[0][0]=r; // Paste saved values from last column to first column
RRacer 0:1f58ecec51d6 78 gm[0][1]=g;
RRacer 0:1f58ecec51d6 79 gm[0][2]=b;
RRacer 0:1f58ecec51d6 80 // Do it again for the lower half
RRacer 0:1f58ecec51d6 81 r=gm[31][3];
RRacer 0:1f58ecec51d6 82 g=gm[31][4];
RRacer 0:1f58ecec51d6 83 b=gm[31][5];
RRacer 0:1f58ecec51d6 84
RRacer 0:1f58ecec51d6 85 for(i=31; i>0; i--) {
RRacer 0:1f58ecec51d6 86 gm[i][3]=gm[i-1][3];
RRacer 0:1f58ecec51d6 87 gm[i][4]=gm[i-1][4];
RRacer 0:1f58ecec51d6 88 gm[i][5]=gm[i-1][5];
RRacer 0:1f58ecec51d6 89 }
RRacer 0:1f58ecec51d6 90 gm[0][3]=r;
RRacer 0:1f58ecec51d6 91 gm[0][4]=g;
RRacer 0:1f58ecec51d6 92 gm[0][5]=b;
RRacer 0:1f58ecec51d6 93 }
RRacer 0:1f58ecec51d6 94
RRacer 0:1f58ecec51d6 95 void WrRow(unsigned char Row)
RRacer 0:1f58ecec51d6 96 {
RRacer 0:1f58ecec51d6 97 // Write specified row (and row+8) to display. Valid input: 0 to 7.
RRacer 0:1f58ecec51d6 98 ABC=7-Row; // Set row address
RRacer 0:1f58ecec51d6 99 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.
RRacer 0:1f58ecec51d6 100 R1 = gm[col][0] & (1<<Row); // Red bit, upper half
RRacer 0:1f58ecec51d6 101 G1 = gm[col][1] & (1<<Row); // Green bit, upper half
RRacer 0:1f58ecec51d6 102 B1 = gm[col][2] & (1<<Row); // Blue bit, upper half
RRacer 0:1f58ecec51d6 103 R2 = gm[col][3] & (1<<Row); // Red bit, lower half
RRacer 0:1f58ecec51d6 104 G2 = gm[col][4] & (1<<Row); // Green bit, lower half
RRacer 0:1f58ecec51d6 105 B2 = gm[col][5] & (1<<Row); // Blue bit, lower half
RRacer 0:1f58ecec51d6 106 CLK = HIGH; // tick (clock bit in)
RRacer 0:1f58ecec51d6 107 CLK = LOW; // tock
RRacer 0:1f58ecec51d6 108 }
RRacer 0:1f58ecec51d6 109 LAT = HIGH; // Latch entire row
RRacer 0:1f58ecec51d6 110 LAT = LOW;
RRacer 0:1f58ecec51d6 111 }
RRacer 0:1f58ecec51d6 112
RRacer 0:1f58ecec51d6 113 void Pset(unsigned char x,unsigned char y, unsigned char c)
RRacer 0:1f58ecec51d6 114 {
RRacer 0:1f58ecec51d6 115 // Set pixel (x,y) to color c
RRacer 0:1f58ecec51d6 116 // Manipulates graphics memory, so you won't see any change til you Paint() it.
RRacer 0:1f58ecec51d6 117 unsigned char ud,l,r0,g0,b0;
RRacer 0:1f58ecec51d6 118 ud=(y & 8)>>3; // 0 = upper half, 1 = lower half
RRacer 0:1f58ecec51d6 119 l=y & 7; // Extract row in upper/lower half
RRacer 0:1f58ecec51d6 120 r0=(c & 4) >>2; // Extract red bit from color
RRacer 0:1f58ecec51d6 121 g0=(c & 2) >>1; // Extract green bit from color
RRacer 0:1f58ecec51d6 122 b0=(c & 1); // Extract blue bit from color
RRacer 0:1f58ecec51d6 123 // *******Removes current bit ******* *Adds bit**
RRacer 0:1f58ecec51d6 124 gm[x][0+3*ud]=(gm[x][0+3*ud] & (255-(1<<(7-l))))+(r0<<(7-l)); // Red byte
RRacer 0:1f58ecec51d6 125 gm[x][1+3*ud]=(gm[x][1+3*ud] & (255-(1<<(7-l))))+(g0<<(7-l)); // Green byte
RRacer 0:1f58ecec51d6 126 gm[x][2+3*ud]=(gm[x][2+3*ud] & (255-(1<<(7-l))))+(b0<<(7-l)); // Blue byte
RRacer 0:1f58ecec51d6 127 }
RRacer 0:1f58ecec51d6 128
RRacer 0:1f58ecec51d6 129 void Paint()
RRacer 0:1f58ecec51d6 130 {
RRacer 0:1f58ecec51d6 131 // Write graphics memory to display
RRacer 0:1f58ecec51d6 132 for(int Row=0; Row<8; Row++) {
RRacer 0:1f58ecec51d6 133 OE = HIGH; // Disable output
RRacer 0:1f58ecec51d6 134 WrRow(Row);
RRacer 0:1f58ecec51d6 135 OE = LOW; // Enable output
RRacer 0:1f58ecec51d6 136 wait_us(500); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
RRacer 0:1f58ecec51d6 137 }
RRacer 0:1f58ecec51d6 138 }
RRacer 0:1f58ecec51d6 139
RRacer 0:1f58ecec51d6 140 int main()
RRacer 0:1f58ecec51d6 141 {
RRacer 0:1f58ecec51d6 142 Init(); // Set things up
RRacer 0:1f58ecec51d6 143 while(1) { // Messy demo loop following...
RRacer 0:1f58ecec51d6 144 CT++;
RRacer 0:1f58ecec51d6 145 if((CT<=2560)||(CT>=2880 && CT<=4160)) {
RRacer 0:1f58ecec51d6 146 Paint(); // Refresh display
RRacer 0:1f58ecec51d6 147 if((CT % 20)==0) ShiftRight(); // After every 20 refresh, do a ShiftRight
RRacer 0:1f58ecec51d6 148 }
RRacer 0:1f58ecec51d6 149 if(CT==2560) {
RRacer 0:1f58ecec51d6 150 for(int c=0; c<8; c++) {
RRacer 0:1f58ecec51d6 151 for(int x=c; x<(31-c); x++) {// Top side
RRacer 0:1f58ecec51d6 152 Pset(x,c,c);
RRacer 0:1f58ecec51d6 153 Paint(); // Display refresh time sets loop duration.
RRacer 0:1f58ecec51d6 154 }
RRacer 0:1f58ecec51d6 155 for(int y=c; y<(15-c); y++) {// Right side
RRacer 0:1f58ecec51d6 156 Pset(31-c,y,c);
RRacer 0:1f58ecec51d6 157 Paint();
RRacer 0:1f58ecec51d6 158 }
RRacer 0:1f58ecec51d6 159 for(int x=(31-c); x>=c; x--) {// Bottom side
RRacer 0:1f58ecec51d6 160 Pset(x,(15-c),c);
RRacer 0:1f58ecec51d6 161 Paint();
RRacer 0:1f58ecec51d6 162 }
RRacer 0:1f58ecec51d6 163 for(int y=(15-c); y>=c; y--) { // Left side
RRacer 0:1f58ecec51d6 164 Pset(c,y,c);
RRacer 0:1f58ecec51d6 165 Paint();
RRacer 0:1f58ecec51d6 166 }
RRacer 0:1f58ecec51d6 167 }
RRacer 0:1f58ecec51d6 168 }
RRacer 0:1f58ecec51d6 169 if(CT>4160) {
RRacer 0:1f58ecec51d6 170 MkPattern(); // Restore original priceless artwork
RRacer 0:1f58ecec51d6 171 CT=0; // Start all over.
RRacer 0:1f58ecec51d6 172 }
RRacer 0:1f58ecec51d6 173 }
RRacer 0:1f58ecec51d6 174 }