title: RaspberryPi Define GPIO Callbacks in a Loop in Python
body: <p>I defined callback functions for each GPIO explicitly and it was working fine. However, this was a bit much boilerplate code for me. Therefore, I just had the idea to realize this initialization in a for-loop:</p>
  <pre class="lang-py prettyprint-override"><code># Configure Switches:
  T = [4,17,18,27,22,23,24,25,5,6]
  for i in range(0,10):
      GPIO.setup(T[i], GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
      GPIO.add_event_detect(T[i], GPIO.BOTH, callback=lambda x: OnButtonPress(i+1), bouncetime=300)
  </code></pre>
  <p>For all buttons that I press the callback function OnButtonPress is called, however always with the button ID 10, independent from which button I press. It seams that the lambda is always called with 10 as parameter. What am I doing wrong here?</p>