How do I alter a sketch polarity to drive a 7x5 dot display

I am trying to use the sketch on this page to drive a 7x5 matrix display. It indicates the option of driving a display of the opposite polarity as a discussion question but does not answer it. I have tried to solve it but without success and my requests to the site for any further info are not replied to.

// mBuf  - 2 dimensional array (7 rows, 5 columns)
            byte mBuf[7][5] = {
                               {0, 0, 1, 0, 0},  // 0
                               {0, 1, 0, 1, 0},  // 1
                               {0, 0, 1, 0, 0},  // 2
                               {0, 0, 1, 0, 0},  // 3
                               {1, 0, 0, 0, 1},  // 4
                               {0, 1, 1, 1, 0},  // 5
                               {0, 0, 1, 0, 0}   // 6
                             };

int rowPins[7] = {2,4,5,6,9,11,12};//{7, 8, 9, 10, 11, 12, 13}; // array that holds row pin assignments
int colPins[5] = {1,3,7,8,10};//{2, 3, 4, 5, 6};           // array that holds column pin assignments

void setup() {
  // put your setup code here, to run once:
for (int c = 0; c < 5; c++)
  {
    pinMode(colPins[c], OUTPUT);                    // initalize column pins
  }

for (int r = 0; r < 7; r++)                                     // initialize row pins
  {
      pinMode(rowPins[r], OUTPUT);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  refreshMatrix();    
}
void refreshMatrix()                        // send the contents of mbuff to the matrix display
{
   for (int c = 0; c < 5; c++)
    {
      setRowPins(c);
      digitalWrite(colPins[c], HIGH);
      delay(2);
      digitalWrite(colPins[c], LOW);
    }

  return;
}
void setRowPins(int c)                      // Set the row pins to mbuff column values
  {
    int r;
    for (r = 0; r < 7; r++)
     {
       digitalWrite(rowPins[r], mBuf[r][c]);
      }
    return;
}

My pins are different to the ones on the web site but I have altered them in the above sketch to fit in with the ones I am using. Can anyone see what alterations are needed to drive a 7x5 LED matrix with ACCR?

It sounds like you have a common X-ode matrix and you want to use code for a common Y-ode. Wire the matrix to a DIO pin so you can forward and reverse bias the diodes. You can turn a diode off by making zero difference in potential across the diode (HIGH--HIGH or LOW--LOW), or reverse biasing.

See if this code meets your needs.
In the simulator I used logic blocks instead of tansistors.
I also changed the Arduino pins to make the simulation easier.
Note: In your project you are using pin 1 of the Arduino.
This is not recommended as it will affect and be influenced by the serial.

And if you are fresh out of Quad 2 input NAND DIPs... changing bias to switch LEDs on and off...

// mBuf  - 2 dimensional array (7 rows, 5 columns)
            byte mBuf[7][5] = {
                               {1,1,0,1,1},  // 0
                               {1,0,1,0,1},  // 1
                               {1,1,0,1,1},  // 2
                               {1,1,0,1,1},  // 3
                               {0,1,1,1,0},  // 4
                               {1,0,0,0,1},  // 5
                               {1,1,0,1,1}   // 6
                             };

int rowPins[7] = {2,4,5,6,9,11,12};//{7, 8, 9, 10, 11, 12, 13}; // array that holds row pin assignments
int colPins[5] = {1,3,7,8,10};//{2, 3, 4, 5, 6};           // array that holds column pin assignments

void setup() {
  // put your setup code here, to run once:
for (int c = 0; c < 5; c++)
  {
    pinMode(colPins[c], OUTPUT);                    // initalize column pins
  }

for (int r = 0; r < 7; r++)                                     // initialize row pins
  {
      pinMode(rowPins[r], OUTPUT);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  refreshMatrix();    
}
void refreshMatrix()                        // send the contents of mbuff to the matrix display
{
   for (int c = 0; c < 5; c++)
    {
      setRowPins(c);
      digitalWrite(colPins[c], LOW);
      delay(2);
      digitalWrite(colPins[c], HIGH);
    }

  return;
}
void setRowPins(int c)                      // Set the row pins to mbuff column values
  {
    int r;
    for (r = 0; r < 7; r++)
     {
       digitalWrite(rowPins[r], mBuf[r][c]);
      }
    return;
}

I think the code you sent me is the same as I already have, with the pins changed.
runaway_pancake
the only change I can see is the line in void (refresh matrix) that turns the colpin low instead of high, this fails to change the output polarity, the leds still light when connected the wrong way round but not when corrected.

@matelot
Yes, the code is the same.
But if you opened the simulator and run it, you will see that it works with an ACCR matrix, according to your needs.
If you notice, I built a 5x7 matrix with connections similar to ACCR.
If this doesn't meet your needs, then explain better what it is and maybe we can help you.

I am asking for help because my code doesn't work?
the link you sent me uses nand gates, they invert the input.
I will see if I have some spare nand gates tomorrow, or even invertors.
For some reason just inverting the code as runaway_pancake has suggested doesn't work.

Have you even looked at the simulation I posted?

The main code is a handful of lines. The four or five functions show how to use it.

@matelot
In the schematic of the link you posted, the author uses transistors in the columns.
Transistors T1 to T5 also invert the output, (not input).
They perform the same function as the NAND blocks I used in the simulator.

When the BASEs of the transistors are HIGH, the COLLECTORS are LOW.
NAND also, when the INPUTS are HIGH the OUTPUT are LOW.

As the simulator does not provide transistors, I used NAND blocks.

The first simulation I used CCAR matrix, in this second simulation I am using ACCR.
Test this new simulation and see if it meets your needs.
In the code I simply inverted the output of the lines of this "for:

for (int c = 0; c < 5; c++)
   {
     setRowPins(c);
     digitalWrite(colPins[c], LOW);
     delay(2);
     digitalWrite(colPins[c], HIGH);
   }

and used the sign "!' to invert the output of this line:

 digitalWrite(rowPins[r], !mBuf[r][c]);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.