import RPi.GPIO as GPIO, sys from time import sleep leds = [4, 17, 27] buttons = [18, 23, 24, 25] GPIO.setmode(GPIO.BCM) def setupLED(ledNumber): GPIO.setup(leds[ledNumber], GPIO.OUT) def setupBUTTON(buttonNumber): GPIO.setup(buttons[buttonNumber], GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.add_event_detect(buttons[buttonNumber], GPIO.RISING, callback=led1, bouncetime=300) def led1(): print("LED ON") try: for leds in leds: print(leds) setupLED(leds) setupBUTTON(0) setupBUTTON(1) setupBUTTON(2) setupBUTTON(3) while True: sleep(0.001) except KeyboardInterrupt: print("\nKeyboard Exit.") except: print("Unexpected error:", sys.exc_info()[0]) raise finally: GPIO.cleanup()
The above is a very simple bit of code on a Raspberry, in python and if you look at the setupLED(leds) on line 22 this is where it fails but I just can't get my head around why if I write it out in long format (setupLED(0), setupLED(1) etc..) it works...
Can someone point this numpty in the right direction?