-2
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

Root
  • 1
  • It seems that `def LEDOn(self , column , rows):` requires 3 parameters and you're using only 2. `led.LEDOn(L1 , row)` – McNets Dec 20 '16 at 20:46
  • 3
    @mcNets, no, that's normal. The `self` argument is supplied implicitly when doing a method call. – Kevin Dec 20 '16 at 20:50
  • Possible duplicate of [How do I create a variable number of variables?](http://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) – Barmar Dec 20 '16 at 21:09

1 Answers1

2

row = "R" + str(i) doesn't cause row to refer to any of your variables whose name starts with "R". You're effectively doing led.LEDOn(L1, "R1") when you need to be doing led.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

Rs = [9, 18, 23, 24, 25, 8, 7]

At the top of your file, then

for R in Rs:
    led.LEDOn(L1, R)

In your function.

This has the additional benefit of making your pinClean method a lot shorter, too:

def pinClean(self):
    for L in Ls:
        pi.set_PWM_dutycycle(L, Off)
    for R in Rs:
        pi.set_PWM_dutycycle(R, Off)

(... Provided you also decide to make your L variables into a list)

Community
  • 1
  • 1
Kevin
  • 74,910
  • 12
  • 133
  • 166