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

Dependencies:   SDFileSystem mbed

Committer:
chirashi
Date:
Mon Oct 20 13:07:52 2014 +0000
Revision:
5:532937f20397
Parent:
4:245f17936b1a
Child:
6:e6cb4a476422
; 65; ;

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
chirashi 2:c1a9a2a0885d 24 BusOut ABC(D8,D9,D10); // Row address.
chirashi 2:c1a9a2a0885d 25 DigitalOut CLK(D11); // Data clock - rising edge
chirashi 2:c1a9a2a0885d 26 DigitalOut LAT(D12); // Data latch - active low (pulse up after data load)
chirashi 2:c1a9a2a0885d 27 DigitalOut OE(D13); // Output enable - active low (hold high during data load, bring low after LAT pulse)
chirashi 2:c1a9a2a0885d 28 DigitalOut R1(D2); // RED Serial in for upper half
chirashi 2:c1a9a2a0885d 29 DigitalOut R2(D3); // RED Serial in for lower half
chirashi 2:c1a9a2a0885d 30 DigitalOut G1(D4); // GREEN Serial in for upper half
chirashi 2:c1a9a2a0885d 31 DigitalOut G2(D5); // GREEN Serial in for lower half
chirashi 2:c1a9a2a0885d 32 DigitalOut B1(D6); // BLUE Serial in for upper half
chirashi 2:c1a9a2a0885d 33 DigitalOut B2(D7); // 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
chirashi 4:245f17936b1a 38 const int LEDBuffer [16][32] = {
chirashi 4:245f17936b1a 39 {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},
chirashi 4:245f17936b1a 40 {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},
chirashi 4:245f17936b1a 41 {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},
chirashi 4:245f17936b1a 42 {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},
chirashi 4:245f17936b1a 43 {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},
chirashi 4:245f17936b1a 44 {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},
chirashi 4:245f17936b1a 45 {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},
chirashi 4:245f17936b1a 46 {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},
chirashi 4:245f17936b1a 47 {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},
chirashi 4:245f17936b1a 48 {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},
chirashi 4:245f17936b1a 49 {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},
chirashi 4:245f17936b1a 50 {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},
chirashi 4:245f17936b1a 51 {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},
chirashi 4:245f17936b1a 52 {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},
chirashi 4:245f17936b1a 53 {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},
chirashi 4:245f17936b1a 54 {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}
chirashi 4:245f17936b1a 55 };
chirashi 4:245f17936b1a 56
chirashi 4:245f17936b1a 57
chirashi 4:245f17936b1a 58
RRacer 0:1f58ecec51d6 59 void MkPattern() // Fill graphics buffer with colorful test pattern.
RRacer 0:1f58ecec51d6 60 {
RRacer 0:1f58ecec51d6 61 unsigned int col,r,g,b;
RRacer 0:1f58ecec51d6 62 r=0x0f0f0f0f;
RRacer 0:1f58ecec51d6 63 g=0x33333333;
RRacer 0:1f58ecec51d6 64 b=0x55555555;
RRacer 0:1f58ecec51d6 65 for(col=0; col<32; col++) {
RRacer 0:1f58ecec51d6 66 gm[col][0]=(r>>(col % 8)) & 0xff; // Shift red value and mask out LSB.
RRacer 0:1f58ecec51d6 67 gm[col][1]=(g>>(col % 8)) & 0xff; // Shift green value and mask out LSB.
RRacer 0:1f58ecec51d6 68 gm[col][2]=(b>>(col % 8)) & 0xff; // Shift blue value and mask out LSB.
RRacer 0:1f58ecec51d6 69 gm[col][3]=gm[col][0]; // Copy top red byte to bottom red byte.
RRacer 0:1f58ecec51d6 70 gm[col][4]=gm[col][1]; // Copy top green byte to bottom green byte.
RRacer 0:1f58ecec51d6 71 gm[col][5]=gm[col][2]; // Copy top blue byte to bottom blue byte.
RRacer 0:1f58ecec51d6 72 }
RRacer 0:1f58ecec51d6 73 }
RRacer 0:1f58ecec51d6 74
RRacer 0:1f58ecec51d6 75 void Init()
RRacer 0:1f58ecec51d6 76 {
RRacer 0:1f58ecec51d6 77 // Set up things to a known state
RRacer 0:1f58ecec51d6 78 CLK = LOW;
RRacer 0:1f58ecec51d6 79 LAT = LOW;
RRacer 0:1f58ecec51d6 80 OE = HIGH; //display off
RRacer 0:1f58ecec51d6 81 ABC = 0;
RRacer 0:1f58ecec51d6 82 CT=0;
RRacer 0:1f58ecec51d6 83 MkPattern();
RRacer 0:1f58ecec51d6 84 }
RRacer 0:1f58ecec51d6 85
RRacer 0:1f58ecec51d6 86 void ShiftRight()
RRacer 0:1f58ecec51d6 87 {
RRacer 0:1f58ecec51d6 88 unsigned char i,r,g,b;
RRacer 0:1f58ecec51d6 89 r=gm[31][0]; // Save value of last column (top half)
RRacer 0:1f58ecec51d6 90 g=gm[31][1];
RRacer 0:1f58ecec51d6 91 b=gm[31][2];
RRacer 0:1f58ecec51d6 92
RRacer 0:1f58ecec51d6 93 for(i=31; i>0; i--) { // Copy value of column n to column n-1
RRacer 0:1f58ecec51d6 94 gm[i][0]=gm[i-1][0];
RRacer 0:1f58ecec51d6 95 gm[i][1]=gm[i-1][1];
RRacer 0:1f58ecec51d6 96 gm[i][2]=gm[i-1][2];
RRacer 0:1f58ecec51d6 97 }
RRacer 0:1f58ecec51d6 98 gm[0][0]=r; // Paste saved values from last column to first column
RRacer 0:1f58ecec51d6 99 gm[0][1]=g;
RRacer 0:1f58ecec51d6 100 gm[0][2]=b;
RRacer 0:1f58ecec51d6 101 // Do it again for the lower half
RRacer 0:1f58ecec51d6 102 r=gm[31][3];
RRacer 0:1f58ecec51d6 103 g=gm[31][4];
RRacer 0:1f58ecec51d6 104 b=gm[31][5];
RRacer 0:1f58ecec51d6 105
RRacer 0:1f58ecec51d6 106 for(i=31; i>0; i--) {
RRacer 0:1f58ecec51d6 107 gm[i][3]=gm[i-1][3];
RRacer 0:1f58ecec51d6 108 gm[i][4]=gm[i-1][4];
RRacer 0:1f58ecec51d6 109 gm[i][5]=gm[i-1][5];
RRacer 0:1f58ecec51d6 110 }
RRacer 0:1f58ecec51d6 111 gm[0][3]=r;
RRacer 0:1f58ecec51d6 112 gm[0][4]=g;
RRacer 0:1f58ecec51d6 113 gm[0][5]=b;
RRacer 0:1f58ecec51d6 114 }
RRacer 0:1f58ecec51d6 115
RRacer 0:1f58ecec51d6 116 void WrRow(unsigned char Row)
RRacer 0:1f58ecec51d6 117 {
RRacer 0:1f58ecec51d6 118 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 2:c1a9a2a0885d 119 ABC = 7-Row; // Set row address
RRacer 0:1f58ecec51d6 120 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.
chirashi 4:245f17936b1a 121 //R1 = gm[col][0] & (1<<Row); // Red bit, upper half
chirashi 4:245f17936b1a 122 //G1 = gm[col][1] & (1<<Row); // Green bit, upper half
chirashi 4:245f17936b1a 123 //B1 = gm[col][2] & (1<<Row); // Blue bit, upper half
chirashi 4:245f17936b1a 124 //R2 = gm[col][3] & (1<<Row); // Red bit, lower half
chirashi 4:245f17936b1a 125 //G2 = gm[col][4] & (1<<Row); // Green bit, lower half
chirashi 4:245f17936b1a 126 //B2 = gm[col][5] & (1<<Row); // Blue bit, lower half
chirashi 5:532937f20397 127
chirashi 4:245f17936b1a 128 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 4:245f17936b1a 129 R1 = 1;
chirashi 4:245f17936b1a 130 G1 = 1;
chirashi 5:532937f20397 131 B1 = 1;
chirashi 4:245f17936b1a 132 }else{
chirashi 4:245f17936b1a 133 R1 = 0;
chirashi 5:532937f20397 134 G1 = 1;
chirashi 4:245f17936b1a 135 B1 = 0;
chirashi 4:245f17936b1a 136 }
chirashi 4:245f17936b1a 137
chirashi 4:245f17936b1a 138 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 4:245f17936b1a 139 R2 = 1;
chirashi 5:532937f20397 140 G2 = 1;
chirashi 5:532937f20397 141 B2 = 1;
chirashi 4:245f17936b1a 142 }else{
chirashi 4:245f17936b1a 143 R2 = 0;
chirashi 5:532937f20397 144 G2 = 1;
chirashi 5:532937f20397 145 B2 = 1;
chirashi 5:532937f20397 146 }
chirashi 4:245f17936b1a 147
chirashi 4:245f17936b1a 148 CLK = HIGH; // tick (clock bit in)
chirashi 4:245f17936b1a 149 CLK = LOW; // tock
chirashi 4:245f17936b1a 150 }
chirashi 4:245f17936b1a 151 LAT = HIGH; // Latch entire row
chirashi 4:245f17936b1a 152 LAT = LOW;
chirashi 4:245f17936b1a 153 }
chirashi 4:245f17936b1a 154
chirashi 4:245f17936b1a 155 void WrRow2(unsigned char Row)
chirashi 4:245f17936b1a 156 {
chirashi 4:245f17936b1a 157 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 4:245f17936b1a 158 ABC = 7-Row; // Set row address
chirashi 4:245f17936b1a 159 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.
chirashi 5:532937f20397 160
chirashi 5:532937f20397 161 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 5:532937f20397 162 R1 = 1;
chirashi 5:532937f20397 163 G1 = 1;
chirashi 5:532937f20397 164 B1 = 1;
chirashi 5:532937f20397 165 }else{
chirashi 5:532937f20397 166 R1 = 0;
chirashi 5:532937f20397 167 G1 = 1;
chirashi 5:532937f20397 168 B1 = 0;
chirashi 5:532937f20397 169 }
chirashi 5:532937f20397 170
chirashi 5:532937f20397 171 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 5:532937f20397 172 R2 = 1;
chirashi 5:532937f20397 173 G2 = 1;
chirashi 5:532937f20397 174 B2 = 1;
chirashi 5:532937f20397 175 }else{
chirashi 5:532937f20397 176 R2 = 0;
chirashi 5:532937f20397 177 G2 = 1;
chirashi 5:532937f20397 178 B2 = 1;
chirashi 5:532937f20397 179 }
chirashi 5:532937f20397 180
chirashi 5:532937f20397 181 CLK = HIGH; // tick (clock bit in)
chirashi 5:532937f20397 182 CLK = LOW; // tock
chirashi 5:532937f20397 183 }
chirashi 5:532937f20397 184 LAT = HIGH; // Latch entire row
chirashi 5:532937f20397 185 LAT = LOW;
chirashi 5:532937f20397 186 }
chirashi 5:532937f20397 187
chirashi 5:532937f20397 188 void WrRow3(unsigned char Row)
chirashi 5:532937f20397 189 {
chirashi 5:532937f20397 190 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 5:532937f20397 191 ABC = 7-Row; // Set row address
chirashi 5:532937f20397 192 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.
chirashi 5:532937f20397 193
chirashi 5:532937f20397 194 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 5:532937f20397 195 R1 = 1;
chirashi 5:532937f20397 196 G1 = 1;
chirashi 5:532937f20397 197 B1 = 1;
chirashi 5:532937f20397 198 }else{
chirashi 5:532937f20397 199 R1 = 0;
chirashi 5:532937f20397 200 G1 = 0;
chirashi 5:532937f20397 201 B1 = 0;
chirashi 5:532937f20397 202 }
chirashi 5:532937f20397 203
chirashi 5:532937f20397 204 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 5:532937f20397 205 R2 = 1;
chirashi 5:532937f20397 206 G2 = 1;
chirashi 5:532937f20397 207 B2 = 1;
chirashi 5:532937f20397 208 }else{
chirashi 5:532937f20397 209 R2 = 0;
chirashi 5:532937f20397 210 G2 = 0;
chirashi 5:532937f20397 211 B2 = 1;
chirashi 5:532937f20397 212 }
chirashi 5:532937f20397 213
chirashi 5:532937f20397 214 CLK = HIGH; // tick (clock bit in)
chirashi 5:532937f20397 215 CLK = LOW; // tock
chirashi 5:532937f20397 216 }
chirashi 5:532937f20397 217 LAT = HIGH; // Latch entire row
chirashi 5:532937f20397 218 LAT = LOW;
chirashi 5:532937f20397 219 }
chirashi 5:532937f20397 220
chirashi 5:532937f20397 221 void WrRow4(unsigned char Row)
chirashi 5:532937f20397 222 {
chirashi 5:532937f20397 223 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 5:532937f20397 224 ABC = 7-Row; // Set row address
chirashi 5:532937f20397 225 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.
chirashi 5:532937f20397 226
chirashi 5:532937f20397 227 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 5:532937f20397 228 R1 = 1;
chirashi 5:532937f20397 229 G1 = 1;
chirashi 5:532937f20397 230 B1 = 1;
chirashi 5:532937f20397 231 }else{
chirashi 5:532937f20397 232 R1 = 0;
chirashi 5:532937f20397 233 G1 = 0;
chirashi 5:532937f20397 234 B1 = 0;
chirashi 5:532937f20397 235 }
chirashi 5:532937f20397 236
chirashi 5:532937f20397 237 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 5:532937f20397 238 R2 = 1;
chirashi 5:532937f20397 239 G2 = 1;
chirashi 5:532937f20397 240 B2 = 1;
chirashi 5:532937f20397 241 }else{
chirashi 5:532937f20397 242 R2 = 0;
chirashi 5:532937f20397 243 G2 = 0;
chirashi 5:532937f20397 244 B2 = 0;
chirashi 5:532937f20397 245 }
chirashi 5:532937f20397 246
chirashi 5:532937f20397 247 CLK = HIGH; // tick (clock bit in)
chirashi 5:532937f20397 248 CLK = LOW; // tock
chirashi 5:532937f20397 249 }
chirashi 5:532937f20397 250 LAT = HIGH; // Latch entire row
chirashi 5:532937f20397 251 LAT = LOW;
chirashi 5:532937f20397 252 }
chirashi 5:532937f20397 253
chirashi 5:532937f20397 254 void WrRow5(unsigned char Row)
chirashi 5:532937f20397 255 {
chirashi 5:532937f20397 256 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 5:532937f20397 257 ABC = 7-Row; // Set row address
chirashi 5:532937f20397 258 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.
chirashi 5:532937f20397 259
chirashi 4:245f17936b1a 260 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 4:245f17936b1a 261 R1 = 1;
chirashi 4:245f17936b1a 262 G1 = 1;
chirashi 4:245f17936b1a 263 B1 = 1;
chirashi 4:245f17936b1a 264 }else{
chirashi 4:245f17936b1a 265 R1 = 0;
chirashi 4:245f17936b1a 266 G1 = 0;
chirashi 4:245f17936b1a 267 B1 = 0;
chirashi 4:245f17936b1a 268 }
chirashi 4:245f17936b1a 269
chirashi 4:245f17936b1a 270 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 4:245f17936b1a 271 R2 = 1;
chirashi 5:532937f20397 272 G2 = 1;
chirashi 4:245f17936b1a 273 B2 = 1;
chirashi 4:245f17936b1a 274 }else{
chirashi 4:245f17936b1a 275 R2 = 0;
chirashi 4:245f17936b1a 276 G2 = 0;
chirashi 4:245f17936b1a 277 B2 = 0;
chirashi 4:245f17936b1a 278 }
chirashi 5:532937f20397 279
chirashi 5:532937f20397 280 CLK = HIGH; // tick (clock bit in)
chirashi 5:532937f20397 281 CLK = LOW; // tock
chirashi 5:532937f20397 282 }
chirashi 5:532937f20397 283 LAT = HIGH; // Latch entire row
chirashi 5:532937f20397 284 LAT = LOW;
chirashi 5:532937f20397 285 }
chirashi 5:532937f20397 286
chirashi 5:532937f20397 287 void WrRow6(unsigned char Row)
chirashi 5:532937f20397 288 {
chirashi 5:532937f20397 289 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 5:532937f20397 290 ABC = 7-Row; // Set row address
chirashi 5:532937f20397 291 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.
chirashi 5:532937f20397 292
chirashi 5:532937f20397 293 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 5:532937f20397 294 R1 = 1;
chirashi 5:532937f20397 295 G1 = 1;
chirashi 5:532937f20397 296 B1 = 1;
chirashi 5:532937f20397 297 }else{
chirashi 5:532937f20397 298 R1 = 0;
chirashi 5:532937f20397 299 G1 = 0;
chirashi 5:532937f20397 300 B1 = 0;
chirashi 5:532937f20397 301 }
chirashi 5:532937f20397 302
chirashi 5:532937f20397 303 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 5:532937f20397 304 R2 = 1;
chirashi 5:532937f20397 305 G2 = 1;
chirashi 5:532937f20397 306 B2 = 1;
chirashi 5:532937f20397 307 }else{
chirashi 5:532937f20397 308 R2 = 0;
chirashi 5:532937f20397 309 G2 = 0;
chirashi 5:532937f20397 310 B2 = 0;
chirashi 5:532937f20397 311 }
chirashi 5:532937f20397 312
RRacer 0:1f58ecec51d6 313 CLK = HIGH; // tick (clock bit in)
RRacer 0:1f58ecec51d6 314 CLK = LOW; // tock
RRacer 0:1f58ecec51d6 315 }
RRacer 0:1f58ecec51d6 316 LAT = HIGH; // Latch entire row
RRacer 0:1f58ecec51d6 317 LAT = LOW;
RRacer 0:1f58ecec51d6 318 }
RRacer 0:1f58ecec51d6 319
chirashi 5:532937f20397 320 void WrRow7(unsigned char Row)
chirashi 5:532937f20397 321 {
chirashi 5:532937f20397 322 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 5:532937f20397 323 ABC = 7-Row; // Set row address
chirashi 5:532937f20397 324 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.
chirashi 5:532937f20397 325
chirashi 5:532937f20397 326 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 5:532937f20397 327 R1 = 1;
chirashi 5:532937f20397 328 G1 = 1;
chirashi 5:532937f20397 329 B1 = 1;
chirashi 5:532937f20397 330 }else{
chirashi 5:532937f20397 331 R1 = 0;
chirashi 5:532937f20397 332 G1 = 0;
chirashi 5:532937f20397 333 B1 = 0;
chirashi 5:532937f20397 334 }
chirashi 5:532937f20397 335
chirashi 5:532937f20397 336 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 5:532937f20397 337 R2 = 1;
chirashi 5:532937f20397 338 G2 = 1;
chirashi 5:532937f20397 339 B2 = 1;
chirashi 5:532937f20397 340 }else{
chirashi 5:532937f20397 341 R2 = 0;
chirashi 5:532937f20397 342 G2 = 0;
chirashi 5:532937f20397 343 B2 = 0;
chirashi 5:532937f20397 344 }
chirashi 5:532937f20397 345
chirashi 5:532937f20397 346 CLK = HIGH; // tick (clock bit in)
chirashi 5:532937f20397 347 CLK = LOW; // tock
chirashi 5:532937f20397 348 }
chirashi 5:532937f20397 349 LAT = HIGH; // Latch entire row
chirashi 5:532937f20397 350 LAT = LOW;
chirashi 5:532937f20397 351 }
chirashi 5:532937f20397 352
chirashi 5:532937f20397 353 void WrRow8(unsigned char Row)
chirashi 5:532937f20397 354 {
chirashi 5:532937f20397 355 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 5:532937f20397 356 ABC = 7-Row; // Set row address
chirashi 5:532937f20397 357 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.
chirashi 5:532937f20397 358
chirashi 5:532937f20397 359 if (LEDBuffer [(7-Row)][col] == 2){
chirashi 5:532937f20397 360 R1 = 1;
chirashi 5:532937f20397 361 G1 = 1;
chirashi 5:532937f20397 362 B1 = 1;
chirashi 5:532937f20397 363 }else{
chirashi 5:532937f20397 364 R1 = 0;
chirashi 5:532937f20397 365 G1 = 0;
chirashi 5:532937f20397 366 B1 = 0;
chirashi 5:532937f20397 367 }
chirashi 5:532937f20397 368
chirashi 5:532937f20397 369 if (LEDBuffer [(15-Row)][col] == 2){
chirashi 5:532937f20397 370 R2 = 1;
chirashi 5:532937f20397 371 G2 = 1;
chirashi 5:532937f20397 372 B2 = 1;
chirashi 5:532937f20397 373 }else{
chirashi 5:532937f20397 374 R2 = 0;
chirashi 5:532937f20397 375 G2 = 0;
chirashi 5:532937f20397 376 B2 = 0;
chirashi 5:532937f20397 377 }
chirashi 5:532937f20397 378
chirashi 5:532937f20397 379 CLK = HIGH; // tick (clock bit in)
chirashi 5:532937f20397 380 CLK = LOW; // tock
chirashi 5:532937f20397 381 }
chirashi 5:532937f20397 382 LAT = HIGH; // Latch entire row
chirashi 5:532937f20397 383 LAT = LOW;
chirashi 5:532937f20397 384 }
chirashi 3:6dbbc0130e96 385 void WrRowOFF(unsigned char Row)
chirashi 3:6dbbc0130e96 386 {
chirashi 3:6dbbc0130e96 387 // Write specified row (and row+8) to display. Valid input: 0 to 7.
chirashi 3:6dbbc0130e96 388 ABC = 7-Row; // Set row address
chirashi 3:6dbbc0130e96 389 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.
chirashi 3:6dbbc0130e96 390 R1 = 0; // Red bit, upper half
chirashi 3:6dbbc0130e96 391 G1 = 0; // Green bit, upper half
chirashi 3:6dbbc0130e96 392 B1 = 0; // Blue bit, upper half
chirashi 3:6dbbc0130e96 393 R2 = 0; // Red bit, lower half
chirashi 3:6dbbc0130e96 394 G2 = 0; // Green bit, lower half
chirashi 3:6dbbc0130e96 395 B2 = 0; // Blue bit, lower half
chirashi 3:6dbbc0130e96 396 CLK = HIGH; // tick (clock bit in)
chirashi 3:6dbbc0130e96 397 CLK = LOW; // tock
chirashi 3:6dbbc0130e96 398 }
chirashi 3:6dbbc0130e96 399 LAT = HIGH; // Latch entire row
chirashi 3:6dbbc0130e96 400 LAT = LOW;
chirashi 3:6dbbc0130e96 401 }
chirashi 3:6dbbc0130e96 402
RRacer 0:1f58ecec51d6 403 void Pset(unsigned char x,unsigned char y, unsigned char c)
RRacer 0:1f58ecec51d6 404 {
RRacer 0:1f58ecec51d6 405 // Set pixel (x,y) to color c
RRacer 0:1f58ecec51d6 406 // Manipulates graphics memory, so you won't see any change til you Paint() it.
RRacer 0:1f58ecec51d6 407 unsigned char ud,l,r0,g0,b0;
RRacer 0:1f58ecec51d6 408 ud=(y & 8)>>3; // 0 = upper half, 1 = lower half
RRacer 0:1f58ecec51d6 409 l=y & 7; // Extract row in upper/lower half
RRacer 0:1f58ecec51d6 410 r0=(c & 4) >>2; // Extract red bit from color
RRacer 0:1f58ecec51d6 411 g0=(c & 2) >>1; // Extract green bit from color
RRacer 0:1f58ecec51d6 412 b0=(c & 1); // Extract blue bit from color
RRacer 0:1f58ecec51d6 413 // *******Removes current bit ******* *Adds bit**
RRacer 0:1f58ecec51d6 414 gm[x][0+3*ud]=(gm[x][0+3*ud] & (255-(1<<(7-l))))+(r0<<(7-l)); // Red byte
RRacer 0:1f58ecec51d6 415 gm[x][1+3*ud]=(gm[x][1+3*ud] & (255-(1<<(7-l))))+(g0<<(7-l)); // Green byte
RRacer 0:1f58ecec51d6 416 gm[x][2+3*ud]=(gm[x][2+3*ud] & (255-(1<<(7-l))))+(b0<<(7-l)); // Blue byte
RRacer 0:1f58ecec51d6 417 }
RRacer 0:1f58ecec51d6 418
RRacer 0:1f58ecec51d6 419 void Paint()
RRacer 0:1f58ecec51d6 420 {
RRacer 0:1f58ecec51d6 421 // Write graphics memory to display
chirashi 5:532937f20397 422 //1
RRacer 0:1f58ecec51d6 423 for(int Row=0; Row<8; Row++) {
RRacer 0:1f58ecec51d6 424 OE = HIGH; // Disable output
RRacer 0:1f58ecec51d6 425 WrRow(Row);
chirashi 4:245f17936b1a 426 //WrRow2(Row);
chirashi 5:532937f20397 427 //wait_us(10);
chirashi 5:532937f20397 428 OE = LOW; // Enable output
chirashi 5:532937f20397 429
chirashi 5:532937f20397 430 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 431 }
chirashi 5:532937f20397 432 //2
chirashi 5:532937f20397 433 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 434 OE = HIGH; // Disable output
chirashi 5:532937f20397 435 //WrRow(Row);
chirashi 5:532937f20397 436 WrRow2(Row);
chirashi 5:532937f20397 437 //wait_us(10);
chirashi 5:532937f20397 438 OE = LOW; // Enable output
chirashi 5:532937f20397 439
chirashi 5:532937f20397 440 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 441 }
chirashi 5:532937f20397 442 //3
chirashi 5:532937f20397 443 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 444 OE = HIGH; // Disable output
chirashi 5:532937f20397 445 WrRow3(Row);
chirashi 5:532937f20397 446 //wait_us(10);
chirashi 5:532937f20397 447 OE = LOW; // Enable output
chirashi 5:532937f20397 448
chirashi 5:532937f20397 449 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 450 }
chirashi 5:532937f20397 451 //4
chirashi 5:532937f20397 452 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 453 OE = HIGH; // Disable output
chirashi 5:532937f20397 454 WrRow4(Row);
chirashi 5:532937f20397 455 //wait_us(10);
RRacer 0:1f58ecec51d6 456 OE = LOW; // Enable output
chirashi 4:245f17936b1a 457
chirashi 5:532937f20397 458 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 459 }
chirashi 5:532937f20397 460 //5
chirashi 5:532937f20397 461 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 462 OE = HIGH; // Disable output
chirashi 5:532937f20397 463 WrRow5(Row);
chirashi 5:532937f20397 464 //wait_us(10);
chirashi 5:532937f20397 465 OE = LOW; // Enable output
chirashi 5:532937f20397 466
chirashi 5:532937f20397 467 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 468 }
chirashi 5:532937f20397 469 //6
chirashi 5:532937f20397 470 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 471 OE = HIGH; // Disable output
chirashi 5:532937f20397 472 WrRow6(Row);
chirashi 5:532937f20397 473 //wait_us(10);
chirashi 5:532937f20397 474 OE = LOW; // Enable output
chirashi 5:532937f20397 475
chirashi 5:532937f20397 476 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 4:245f17936b1a 477 }
chirashi 5:532937f20397 478 //7
chirashi 5:532937f20397 479 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 480 OE = HIGH; // Disable output
chirashi 5:532937f20397 481 WrRow7(Row);
chirashi 5:532937f20397 482 //wait_us(10);
chirashi 5:532937f20397 483 OE = LOW; // Enable output
chirashi 5:532937f20397 484
chirashi 5:532937f20397 485 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 486 }
chirashi 5:532937f20397 487 //8
chirashi 5:532937f20397 488 for(int Row=0; Row<8; Row++) {
chirashi 5:532937f20397 489 OE = HIGH; // Disable output
chirashi 5:532937f20397 490 WrRow8(Row);
chirashi 5:532937f20397 491 //wait_us(10);
chirashi 5:532937f20397 492 OE = LOW; // Enable output
chirashi 5:532937f20397 493
chirashi 5:532937f20397 494 wait_us(5); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 5:532937f20397 495 }
chirashi 5:532937f20397 496
chirashi 4:245f17936b1a 497 }
chirashi 4:245f17936b1a 498
chirashi 4:245f17936b1a 499 void Paint2()
chirashi 4:245f17936b1a 500 {
chirashi 4:245f17936b1a 501 // Write graphics memory to display
chirashi 4:245f17936b1a 502 for(int Row=0; Row<8; Row++) {
chirashi 4:245f17936b1a 503 OE = HIGH; // Disable output
chirashi 4:245f17936b1a 504 //WrRow(Row);
chirashi 4:245f17936b1a 505 WrRow2(Row);
chirashi 4:245f17936b1a 506 OE = LOW; // Enable output
chirashi 4:245f17936b1a 507
chirashi 5:532937f20397 508 wait_us(20); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
RRacer 0:1f58ecec51d6 509 }
RRacer 0:1f58ecec51d6 510 }
RRacer 0:1f58ecec51d6 511
chirashi 3:6dbbc0130e96 512
chirashi 3:6dbbc0130e96 513 void PaintOFF()
chirashi 3:6dbbc0130e96 514 {
chirashi 3:6dbbc0130e96 515 // Write graphics memory to display
chirashi 3:6dbbc0130e96 516 for(int Row=0; Row<8; Row++) {
chirashi 3:6dbbc0130e96 517 OE = HIGH; // Disable output
chirashi 3:6dbbc0130e96 518 WrRowOFF(Row);
chirashi 3:6dbbc0130e96 519 OE = LOW; // Enable output
chirashi 4:245f17936b1a 520 wait_us(50); // Wasting some time. Use for whatever else. Probably better with a ticker for the display refresh.
chirashi 3:6dbbc0130e96 521 }
chirashi 3:6dbbc0130e96 522 }
chirashi 3:6dbbc0130e96 523
chirashi 3:6dbbc0130e96 524
chirashi 3:6dbbc0130e96 525
RRacer 0:1f58ecec51d6 526 int main()
RRacer 0:1f58ecec51d6 527 {
RRacer 0:1f58ecec51d6 528 Init(); // Set things up
RRacer 0:1f58ecec51d6 529 while(1) { // Messy demo loop following...
RRacer 0:1f58ecec51d6 530 CT++;
chirashi 3:6dbbc0130e96 531
chirashi 4:245f17936b1a 532 Paint(); // Refresh display
chirashi 5:532937f20397 533 //Paint2(); // Refresh display
chirashi 4:245f17936b1a 534
chirashi 4:245f17936b1a 535 //if((CT<=2560)||(CT>=2880 && CT<=4160)) {
chirashi 4:245f17936b1a 536 // Paint(); // Refresh display
chirashi 4:245f17936b1a 537 // if((CT % 20)==0) ShiftRight(); // After every 20 refresh, do a ShiftRight
chirashi 4:245f17936b1a 538 //}
chirashi 3:6dbbc0130e96 539
chirashi 4:245f17936b1a 540 //if(CT==2560) {
chirashi 4:245f17936b1a 541 // for(int c=0; c<8; c++) {
chirashi 4:245f17936b1a 542 // for(int x=c; x<(31-c); x++) {// Top side
chirashi 4:245f17936b1a 543 // Pset(x,c,c);
chirashi 4:245f17936b1a 544 // Paint(); // Display refresh time sets loop duration.
chirashi 4:245f17936b1a 545 // }
chirashi 4:245f17936b1a 546 // for(int y=c; y<(15-c); y++) {// Right side
chirashi 4:245f17936b1a 547 // Pset(31-c,y,c);
chirashi 4:245f17936b1a 548 // Paint();
chirashi 4:245f17936b1a 549 // }
chirashi 4:245f17936b1a 550 // for(int x=(31-c); x>=c; x--) {// Bottom side
chirashi 4:245f17936b1a 551 // Pset(x,(15-c),c);
chirashi 4:245f17936b1a 552 // Paint();
chirashi 4:245f17936b1a 553 // }
chirashi 4:245f17936b1a 554 // for(int y=(15-c); y>=c; y--) { // Left side
chirashi 4:245f17936b1a 555 // Pset(c,y,c);
chirashi 4:245f17936b1a 556 // Paint();
chirashi 4:245f17936b1a 557 // }
chirashi 4:245f17936b1a 558 // }
chirashi 4:245f17936b1a 559 //}
chirashi 3:6dbbc0130e96 560
RRacer 0:1f58ecec51d6 561 if(CT>4160) {
chirashi 4:245f17936b1a 562 //MkPattern(); // Restore original priceless artwork
RRacer 0:1f58ecec51d6 563 CT=0; // Start all over.
RRacer 0:1f58ecec51d6 564 }
chirashi 3:6dbbc0130e96 565
chirashi 4:245f17936b1a 566 //PaintOFF();
chirashi 5:532937f20397 567 wait_us(10);
RRacer 0:1f58ecec51d6 568 }
chirashi 3:6dbbc0130e96 569
RRacer 0:1f58ecec51d6 570 }