I have a raspberry pi model B+ , and an 8x8 LED matrix(single colored) , so I connected 8 GPIO pins to the 8 row pins of the matrix and another 8 GPIO pins to the 8 colomn pins. Note that I am pretty beginner in this so pardon me for my ignorance. 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. and thats what I did.
def enlight(i, j):
GPIO.output(row[i],GPIO.HIGH)
GPIO.output(col[j],GPIO.LOW)
so this is how it works, if I want the LED of coordinate (2,3) to light up, i would set row2 to HIGH and col3 to LOW.
problem arises in the following scenario. suppose 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 giving HIGH to row0 and row1 and LOW to col0 and col1 , so these 2 pairs of rows and columns are going to intersect in 4 points, hence four points lighting up. to avoid this circumstance , I created a delight()
function which basically does the opposite of enlight()
, i.e setting row to LOW and col to HIGH , hence turning off LED. So this is what I did, in order to light up both (0,0) and (1,1) at once, without any other LEDs turning on.
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 these happen so fast that human eye cant distinguish the turning on and off and sees a constant turning on of two LEDs.
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 simplicity.