Go Down

### Topic: bi color led matrix problem (Read 2317 times)previous topic - next topic

#### patryk

##### Feb 25, 2011, 11:40 pm
i found this code and i'm trying to modify it to work with 8x8 bi color matrix (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203747843/15)
so basically i need to control 8 columns x 16 rows. sounds simple but.....
i've managed to get all 3 colors working but only on half of my matrix (so still 8x8)
could someone take a look at this code and tell me where i made a mistake?
(i'm using arduino mega and directly connected matrix http://www.artronic.pl/o_produkcie.php?id=757?)
Code: [Select]
`/* * Show messages on an 8x8 led matrix (cathode rows) //in my case anode, * scrolling from right to left. * * Pinouts & code by Andrew * see http://arduino.pastebin.com/f35fdf323 * see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1203747843/13#13 */// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)int pins[25]= {-1, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 45, 43, 41, 39, 37, 35, 33, 31, 29, 27, 25, 23};// (for some reason I ended up with different pinouts that Andrew's)// col[xx] of leds = pin yy on led matrixint rows[16] = {pins[11], pins[10], pins[8], pins[7], pins[5], pins[4], pins[2], pins[1], pins[14], pins[15], pins[17], pins[18], pins[20], pins[21], pins[23], pins[24]};// row[xx] of leds = pin yy on led matrixint cols[8] = {pins[22], pins[19], pins[16], pins[13], pins[3], pins[6], pins[9], pins[12]};// Letter definitions based on 5 bit-wise columns (5 x 7 font)#define M1 {65535, 65535, 65535, 65535, 65535}#define M2 {21845, 21845, 21845, 21845, 21845}#define M3 {43690, 43690, 43690, 43690, 43690}#define AAA {21, 68, 324, 68, 21}int dispSpeed = 10; // Constrols scroll speed (1 minimum, way too fast)byte bit[16] = {32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1}; // Used for bit comparisonsbyte colVals[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // Hold display columns (initaly blank)// Define display string hereconst int charNum = 6;     // Number of letters in display stringbyte string[charNum][5] = {M1,AAA,M2,AAA,M3,AAA};void setup() {  for (int i = 1; i <= 24; i++) {   // sets the pins as output    pinMode(pins[i], OUTPUT);  }  for (int col = 0; col < 8; col++) {    // set up cols and rows    digitalWrite(cols[col], LOW);  }  for (int row = 1; row < 16; row++) {    digitalWrite(rows[row], LOW);  }}void loop() {  for (int ltr = 0; ltr < charNum; ltr++){// For each letter in string array    for (int y = 0; y < 6; y++){     // For each columin in letter + one space shiftLeft(); // shifts display columns left if (y < 5){   colVals[7] = string[ltr][y]; }    // add new letter column on right else {colVals[7] = 0; } // or empty space between for (int x = 0; x < dispSpeed; x++){// loop to refresh display x times ton control scrolling   display(); }    }  }}void shiftLeft(){ for (int x = 0; x < 7; x++){   colVals[x] = colVals[x + 1]; }}void display() {   for (int col = 0; col < 8; col++){    for (int row = 0; row < 16; row++){ if (colVals[col] & bit[row]){   digitalWrite(rows[row], LOW);} }    digitalWrite(cols[col], HIGH);  // Turn on column    delay(1);  // Delay for POV    for (int row = 0; row < 16; row++){ digitalWrite(rows[row], HIGH);    }    digitalWrite(cols[col], LOW);  // And off  }}`

#### MarkT

#1
##### Feb 26, 2011, 12:58 am
You're using a byte array to hold 16 bit values but byte is defined as unsigned 8 bit value.  Change it to int or unsigned int.

I'm not sure why you want to store powers of two, they are easy/fast enough to generate on the fly with the shift operator:
Code: [Select]
`int bit = 1 << row ;`
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up