LED Library and PIN Read

Issue #66 resolved
Turgut Guneysu created an issue

Hi John,

While trying to determine PIN status of the LED screen, I noticed that any READ of the digital pins controlling the LEDs causes the corresponding LED position to turn off. And it does not restore unless a CLEAR DISPLAY is executed.

Question is: aren’t the PIN reads supposed to be READONLY !

Here are sample blocks to demonstrate:

Even though the example uses “set user LED”, it issue is valid for any LED activity.

  • Start the loop
  • LED(1,3) lights up
  • Click the say block to read the LED(1,3) status: false / true
  • LED(1,3) turns off. Loop will NOT restore the LED(1,3)
  • Click Clear Display (got to time it to register, then LED(1,3) lights up again

Here are the corresponding LED matrix control pins:

LED(1,3) corresponds to LED 1,2 in the table below, which is controlled by PINS 26 and 4.

Comments (9)

  1. John Maloney repo owner

    Thanks for reporting this phenomenon with your usual careful analysis.

    The issue is that each I/O pin has an internal input/output “mode”. Since it takes time to change the pin mode, the display update code sets it to output mode once and then assumes it stays that way until you clear the display. Reading from the pin changes the mode to “input” and, since the display update code doesn’t change it back to “output”, it stays that way.

    So, although surprising, this isn’t actually a bug. You can’t use the display row and column pins for I/O while also using the display.

    The LED’s are also used to sense light (an LED also works as an inefficient photo diode). So you can’t use the display pins and the “light level” block at the same time, either.

    If you didn’t already know how the row and column pins mapped to LED’s, I believe one could use this phenomenon to reverse engineer it. :-)

  2. Turgut Guneysu reporter

    Thanks John, I understand your explanation. I needed to find out the LED settings.

    Since there is no LED Pin Reporter ala MakeCode, I tried this method, without success.

    I guess I have to wait until the LED library is enhanced with the features you mentioned in an earlier post.

  3. John Maloney repo owner

    It the MakeCode function you’re referring to this one?

    Yes, we may eventually provide that in an extended LED display library.

    FYI, reading the state of the LED pin wouldn’t give you that info because the LED matrix is updated in three phases (row1, row2, row3) each with a different set of column pins enabled. So you’d need to sample the column pin at exactly the right moment to read back the state of an individual LED, and even that probably wouldn’t work because the charge might drain away through the LED before you could sense it. So, a better design is record the state of the LEDs in a list so you can read the value of the LED back from the list when you want it. That’s how the library would work.

  4. John Maloney repo owner

    Question answered. The request for the ability to read the state of a given LED in the 5x5 matrix is covered by issue #49.

  5. Log in to comment