import pigpio
import time
pi = pigpio.pi()
L1 = 2
L2 = 3
L3 = 4
L4 = 17
L5 = 27
L6 = 22
L7 = 10
R1 = 9
R2 = 18
R3 = 23
R4 = 24
R5 = 25
R6 = 8
R7 = 7
On = 255
Off = 0
sleepTime = 0.05
class ledControll:
def pinClean(self):
pi.set_PWM_dutycycle(L1 , Off)
pi.set_PWM_dutycycle(L2 , Off)
pi.set_PWM_dutycycle(L3 , Off)
pi.set_PWM_dutycycle(L4 , Off)
pi.set_PWM_dutycycle(L5 , Off)
pi.set_PWM_dutycycle(L6 , Off)
pi.set_PWM_dutycycle(L7 , Off)
pi.set_PWM_dutycycle(R1 , Off)
pi.set_PWM_dutycycle(R2 , Off)
pi.set_PWM_dutycycle(R3 , Off)
pi.set_PWM_dutycycle(R4 , Off)
pi.set_PWM_dutycycle(R5 , Off)
pi.set_PWM_dutycycle(R6 , Off)
pi.set_PWM_dutycycle(R7 , Off)
def LEDOn(self , column , rows):
pi.set_PWM_dutycycle(column , On)
pi.set_PWM_dutycycle(rows , On)
def LEDOff(self , column , row):
pi.set_PWM_dutycycle(column , Off)
pi.set_PWM_dutycycle(row , Off)
try:
led = ledControll()
while True:
for i in range(1 , 7):
row = "R" + str(i)
led.LEDOn(L1 , row)
except KeyboardInterrupt:
led.pinClean()
pi.stop()
this is my code in python, when i run this i get this error: struct.error: cannot convert argument to integer i want to set R1 to R7 with for in led.LEDOn(L1 , R1 to R7) and when i print row it gives me R1 to R7 i'm new in python
row = "R" + str(i)
doesn't causerow
to refer to any of your variables whose name starts with "R". You're effectively doingled.LEDOn(L1, "R1")
when you need to be doingled.LEDOn(L1, R1)
.You might be thinking, "OK, so how do I get a variable, given a string containing its name?" This is covered in detail in the question How do I create a variable number of variables?, but the short answer is: don't have a bunch of variables that differ only by a number; use a dictionary or list instead.
In your specific case, you might do something like
At the top of your file, then
In your function.
This has the additional benefit of making your
pinClean
method a lot shorter, too:(... Provided you also decide to make your L variables into a list)