home made LED matrix 8cx6r

I built an LED Matrix with some spare LEDS i can get all the LEDS lit up with this code:

int rows[9] = {
  -1,22,23,24,25,26,27,28,29};
int cols[7] = {
  -2,40,41,42,43,44,45};

void setup() 
{
  for (int thisPin = 0; thisPin < 10; thisPin++)
  {
    pinMode(rows[thisPin], OUTPUT);
    pinMode(cols[thisPin], OUTPUT); 
  }
}

void loop()
{
  //rows
digitalWrite(rows[1], HIGH);
digitalWrite(rows[2], HIGH);
digitalWrite(rows[3], HIGH);
digitalWrite(rows[4], HIGH);
digitalWrite(rows[5], HIGH);
digitalWrite(rows[6], HIGH);
digitalWrite(rows[7], HIGH);
digitalWrite(rows[8], HIGH);
//cols
digitalWrite(cols[1], LOW);
digitalWrite(cols[2], LOW);
digitalWrite(cols[3], LOW);
digitalWrite(cols[4], LOW);
digitalWrite(cols[5], LOW);
digitalWrite(cols[6], LOW);
}

but when i try to make the r1-c1 and r2-c2, light up i get four LEDS to light up i’m new to this need help thank you.

John

int rows[9] = {
  -1,22,23,24,25,26,27,28,29};
int cols[7] = {
  -2,40,41,42,43,44,45};

Why negative numbers for the first elements ?

maybe that’s part of the problem ?

I used the Negative numbers so that I don't have to do the (01234567) I can instead do (12345678) its a dummy number that the system dose not recognize but dose not give an error

but when i try to make the r1-c1 and r2-c2, light up i get four LEDS to light up

Yes you will, that's what happens with a matrix.

To get them to light separately you first have to light r1-c1 then turn it off and the light r2-c2, keep doing it rapidly and they look like they are on at the same time. It's called multiplexing and that is the way you drive a matrix.

ok multiplexing ok i need to have them on but not at the same time but at a rate that allows me to see them on with out four LEDS ?? ok explain

For an example of multiplexing a matrix see:- http://www.thebox.myzen.co.uk/Hardware/Econo_Monome.html

Watch out for this one there are no resistors in line with the LEDs and that damages the arduino but the software is OK. http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix

how would i code that, with what ive given. as ive said im pretty new to this and i think im getting confused some were

Take a look at the code sample on the DirectDriveLEDMatrix page

Each time the display function is called it lights up a different row of the led matrix.

http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix?action=sourceblock&ref=1

// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 8) {
    col = 0;
  }
  for (int row = 0; row < 8; row++) {
    if (leds[col][7 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
}

I just whipped this up for an example that just shows the multiplexing. I might have mixed up HIGH and LOW for the columns. There is a commented out delay in the loop function, so if this works, you can uncomment the delay and see it work in super slow motion.

int col=1;
uint8_t buffer[8] = { 224, 32, 248, 184, 168, 232,0,0 };

int rows[9] = {
  -1,22,23,24,25,26,27,28,29};
int cols[7] = {
  -2,40,41,42,43,44,45};

void setup () {
  //columns
  for (int i = 1; i <= 6; i++) {
    pinMode(cols[i], OUTPUT);
    digitalWrite(cols[i], HIGH); //idea is to start off turned off.
  }

  for (int i = 1; i <= 8; i++) {
    pinMode(rows[i], OUTPUT);
    digitalWrite(rows[i], LOW);
  }
  
}
void loop () {
  digitalWrite(cols[col], HIGH);
  col++;
  if (col == 8) {
    col = 0;
  }
  for (int row = 0; row < 8; row++) {
    digitalWrite(rows[row], buffer[row] << 7-col); 
    
  }
  digitalWrite(cols[col], LOW); // Turn whole column on at once (for equal lighting times)
  //delay(1000); 
}

ok so ive got it to be all fancy and multiplex how would i code a cool word across the LEDS ??