5x5 LED Multiplexing Avoid dim out / Fading (e.g. Character X)

Hi all,

i got a 5x5 multiplexing matrix.

When I use this code to switch on all LED in the first row, the LEDs are very bright

  digitalWrite(gndPins[0], LOW);
  for (int thatPin = 0; thatPin < pinCount; thatPin++) {
    digitalWrite(ledPins[thatPin], HIGH);
  }

When I use another way to achieve this, the LED are darker, because of the reset-command:

  for (int time = 2; time <= 2000; time++) {

    digitalWrite(ledPins[0], HIGH);
    digitalWrite(ledPins[1], HIGH);
    digitalWrite(ledPins[2], HIGH);
    digitalWrite(ledPins[3], HIGH);
    digitalWrite(ledPins[4], HIGH);
    digitalWrite(gndPins[0], LOW);
    reset_pins();
  }

I asume the for-loop is necessary if you want to display the character X.
I read that the LEDs musst be switched on and off very rapidly, so that the human eye is not recognizing.

But I have no idea haw to avoid the fading.

Please help.

Regards Mario

try delayMicroseconds(1000); before the reset.

Rule 1: Keep all of the row (ground) pins HIGH when changing column (led) pins, otherwise you will get ghosting.

Rule 2: Set all of the column (led) pins for the current row before setting the row (ground) pin LOW. If you set the row (ground) pin LOW while any column (led) pin from the previous row is HIGH you will get ghosting. If you set all of the column (led) pins LOW but set the row (ground) pin LOW before you set the column (led) pins for the row HIGH then the brightness of each column (led) will depend on the order in which you set the pins HIGH.

Rule 3: Put a small delay between setting the one row (ground) pin LOW and setting it HIGH again. Use a delay that just short of causing flicker. Shorter time will give lower brightness and longer time will produce flicker. In my case of 4 rows the time of 3 mS was right.

Hi Johnwasser,

great!! I will test this.
Regards Mario

@gpop1: I tested your suggestion, but the character X is now display to long :frowning:
Thank you!

Hi johnwasser,

i spend a little time to think about that. From a mathematical point of view it will never be possible that a X will be bright as a horizontal or vertical row.
With an X you have to switch between off and on. So you will have - and if it is in millisenconds - where LEDs are dark. AFAIK the human I can recognize 17 pictures in one second as single pictures. Everything over 17 is a "movie". But there will be also pictures regongnized as dar pictures. In other words: The LED in an X have to share the time they are spending light.
So and X will ever be darker as a row.

Regards
Mario

Mario, I mean no offense, but your post makes no sense. Perhaps your English is not very good, but I think it is mainly because you didn't understand the reply. Right now, the best thing you can do is post your entire sketch, so we can see what you are really doing.

Hi arg,

no problem :grinning: Maybe you will be confused. Sorry for the english.
(As my UNO has an error on PIN 10 the gnd-pins are: 7, 8, 9, 11, 12

Enjoy :wink:

int delayTime = 200;
int effectTime = 10;
int delayTimeLetter = 2000;
int neverChangeDelayTime = 200;
int showTimeCharacter = 800;
int gvCount = 0;
int pinCount = 5;
int startFlag = 0;
int ledPins[] = {
  2, 3, 4, 5, 6
};


int gndPins[] = {
  7, 8, 9, 11, 12
};


//######################################
void setup()
//######################################
{
  Serial.begin(9600);
  // LED Pins und GND-Pins muessen alle auf OUTPUT!
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(ledPins[thisPin], OUTPUT);
  }
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(gndPins[thisPin], OUTPUT);
  }
  reset_pins();
}

//######################################
void reset_pins()
//######################################
{

  delayMicroseconds(200);
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    digitalWrite(ledPins[thisPin], LOW);
    // GND Pins initial auf HIGH = ausgeschaltet
    digitalWrite(gndPins[thisPin], HIGH);
  }
}


//######################################
void reset_GNDpins()
//######################################
{
  delayMicroseconds(200);
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    // GND Pins initial auf HIGH = ausgeschaltet
    digitalWrite(gndPins[thisPin], HIGH);
  }
}

//######################################
void loop()
//######################################
{
X_() ;
}

void X_() {
  reset_pins();
  for (int time = 2; time <= showTimeCharacter; time++) {
    digitalWrite(ledPins[0], HIGH);
    digitalWrite(ledPins[4], HIGH);
    digitalWrite(gndPins[0], LOW); reset_pins();
    digitalWrite(ledPins[1], HIGH);
    digitalWrite(ledPins[3], HIGH);
    digitalWrite(gndPins[1], LOW); reset_pins();
    digitalWrite(ledPins[2], HIGH);
    digitalWrite(gndPins[2], LOW); reset_pins();
    digitalWrite(ledPins[1], HIGH);
    digitalWrite(ledPins[3], HIGH);
    digitalWrite(gndPins[3], LOW); reset_pins();
    digitalWrite(ledPins[0], HIGH);
    digitalWrite(ledPins[4], HIGH);
    digitalWrite(gndPins[4], LOW); reset_pins();
  }
}

void setLed(int led, int gnd) {
  reset_pins();
  digitalWrite(led, HIGH);
  digitalWrite(gnd, LOW);
}
void setLedWithOutReset(int led, int gnd) {
  digitalWrite(led, HIGH);
  digitalWrite(gnd, LOW);
}

Now in better english:

From a mathematical point of view it will never be possible that a X (in a 5x5 LED matrix) will be bright as a horizontal or vertical row (where you do not have to reset pins).

With X (in a 5x5 LED matrix) there have to be toggles between off and on.

So you will have a very very short time where LEDs are dark.

AFAIK the human eye can recognize 17 pictures in one second as single pictures.

Everything more than 17 pictures is recognized as motion (like on TV).

But the eye also recognizes the very small dark series! In other words: The LED in an X have to share the time they are lighting and sometimes they are dark.
The sum of lightning time in a row or column is greater than the sum in a X
Conclusion: X will ever be darker as a row or column (where you do not have to reset pins).

Anybody else understand? :slight_smile:

Hes trying to teach a guy who could probably build a tv from a bunch of old components that a led turned off and on is not as bright as a led that's left on. At no point did john say that the leds would be as bright. In fact john pointed out that they would be dimmer unless you lengthened the delay to a point that would cause flickering.

First thing I noticed in johns post was "In my case of 4 rows the time of 3 mS was right.". That means he has a working code. So I would have gone with the simple arse kissing approach to get john to post a code in the hope hes written something I could understand.

I liked this response

@gpop1: I tested your suggestion, but the character X is now display to long :frowning:
Thank you!

hmmmm did you try to reduce the delay?

@gpop1: Good suggestion
@ Johnwater: Do you have some sample code (e.g. 5 x 5 multiplex)?
@aarg: I just wanted to point out, that a code, that has to turn of and on, to display e.g.

  1. X000X
  2. 0X00X
  3. 00X00
  4. 0X0X0
  5. X000X

can never be as bright as a code that has NOT to turn off/on like:
XXXXX
00000
00000
00000
00000

But my assumption was wrong.
There is a workaround

Instead of

  1. switch on X000X > reset pins
  2. switch on 0X00X > reset pins
  3. switch on 00X00 > reset pins
  4. switch on 0X0X0 > reset pins
  5. switch on X000X > reset pins

you could use

  1. switch on X000X
  2. switch on 0X00X > reset (1) : col 1, col5, row 1, row 5 > delayMicros
  3. switch on 00X00 > reset (2): col2, col4, row 2, row 4 > delayMicros
  4. switch on 0X0X0 > reset (3): col3, row 3 > delayMicros
  5. switch on X000X > reset (4): col2, col4, row 2, row 4 > delayMicros

In this case two! rows are ON for some microseconds.

I hope you understand :roll_eyes:

Regards
Mario