# bi color led matrix problem

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?)

``````/*
* 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 matrix
int 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 matrix
int 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 comparisons
byte colVals[8] = {0, 0, 0, 0, 0, 0, 0, 0};	 // Hold display columns (initaly blank)

// Define display string here
const int charNum = 6;				Â  Â  // Number of letters in display string
byte 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
Â  }
}
``````

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:

``````int bit = 1 << row ;
``````