I have a raspberry pi model B+ and an 8x8 LED single color matrix. I connected 8 GPIO pins to the 8 row pins of the matrix and another 8 GPIO pins to the 8 column pins. Note that I am a beginner in this, so have some questions. I have observed by a few tests that if I assign Vcc (HIGH) to the rows and ground (LOW) to the colomn, the LED lights up.
def enlight(i, j):
GPIO.output(row[i],GPIO.HIGH)
GPIO.output(col[j],GPIO.LOW)
If I want the LED of coordinate (2,3) to light up, I would set row2 to HIGH and col3 to LOW.
The problem arises in the following scenario. I want two LEDS i.e (0,0)
and (1,1)
to turn on at once.
enlight(0,0)
enlight(1,1)
but instead of only these two, I have two more LEDs turned on i.e (0,1)
and (1,0)
; which is quite reasonable because I am setting row0 and row1 HIGH and col0 and col1 LOW. So these 2 pairs of rows and columns are going to intersect in 4 points, hence four points lighting up. To avoid this , I created a delight()
function which basically does the opposite of enlight()
, i.e setting row to LOW and col to HIGH, turning off LED. In order to light up both (0,0) and (1,1) at once, without any other LEDs turning on, I command it to:
while true:
enlight(0,0)
delight(0,0)
enlight(1,1)
delight(1,1)
By this, an infinite loop occurs and (0,0) LED is blinking infinitely and just at the moment (0,0) LED is turning off, LED(1,1) is turning on. All of this happen so fast that human eye can't distinguish the blinking and instead sees both LEDs constantly on.
My question is, is this "trick" actually a good trick? Is this how major programs related to LED matrix are done? Or is there any other ways to do so? If there is, please explain in simple terms.