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):

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.


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:

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.


1 Answer 1


You need to use Python's time module.

import time
import RPi.GPIO as GPIO

...  # setup the board and your functions here

while True:
    enlight(0,0)   # on 0,0
    time.sleep(1)  # pause
    delight(0,0)   # off 0,0
    time.sleep(1)  # pause
    enlight(1,1)   # on 1,1
    time.sleep(1)  # pause
    delight(1,1)   # off 1,1
    time.sleep(1)  # pause

time.sleep(1) creates a one second pause.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.