0

I'm trying to get an int into my variable for my GPIO pin, but I just don't know how to fit it in.

From the documentation: GPIO "channel must be an integer or list/tuple of integers"

The button_number comes in as a int from an above part code. And part of the code I'm working with looks as follows:

button1 = 27
GPIO.setup(button + button_number, GPIO.OUT)
GPIO.output(button + button_number, GPIO.LOW)

What I'm hoping to accomplish is adding the int number together with the button "pre-text" and get it recognized as the variable that's saved above.

Running this I get an error:

NameError: global name 'button' is not defined

I've also tried:

GPIO.output("button" + button_number, GPIO.LOW)

&

pin = "button" + button_number
GPIO.setup(int(pin), GPIO.OUT)

I'm running out of idea's. Please help!

user5740843
  • 1,540
  • 5
  • 22
  • 42
  • I already answered you in your previous deleted question, have you tried that? – Caumons Dec 27 '16 at 17:06
  • I realized i didn't ask the question properly and thus deleted it and asked it more clearly. @Caumons, Thank you for your suggestion Caumons, and yes I did try it but I couldn't make it work. – user5740843 Dec 27 '16 at 17:08
  • The answer to this is question is always the same: use a dict. See the [accepted answer](http://stackoverflow.com/a/1373185/104349) to the duplicate question (unfortunately some of the other answers give pretty poor advice). – Daniel Roseman Dec 27 '16 at 17:26

0 Answers0