Close

Software-only solution

A project log for Deghosting multiplexed LEDs

LEDs also act as tiny capacitors and this can be a source of them lighting up when you don't want them to

mihaicuciucmihai.cuciuc 11/07/2021 at 16:190 Comments

Paul suggested an alternate solution, namely to turn off LEDs by setting them to high impedance instead of 0V. That way the tiny LED capacitances have no way to charge and thus no ghosting. I tried it and it works! Awesome "zero extra components" solution, fixing it in software.

Here's the relevant change to the sketch that does just that:

  // turn off all LEDs by turning them to HiZ
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);

  // Turn on required LEDs
  if (mask[pattern] & 0x01) { pinMode(A0, OUTPUT); digitalWrite(A0, HIGH); }
  if (mask[pattern] & 0x02) { pinMode(A1, OUTPUT); digitalWrite(A1, HIGH); }
  if (mask[pattern] & 0x04) { pinMode(A2, OUTPUT); digitalWrite(A2, HIGH); }
  if (mask[pattern] & 0x08) { pinMode(A3, OUTPUT); digitalWrite(A3, HIGH); }
  if (mask[pattern] & 0x10) { pinMode(A4, OUTPUT); digitalWrite(A4, HIGH); }
  if (mask[pattern] & 0x20) { pinMode(A5, OUTPUT); digitalWrite(A5, HIGH); }

Discussions