Advertisement
schuetz

buttonInterrupt.py

May 4th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2.  
  3. button1_sensor_pin = 27
  4. button2_sensor_pin = 22
  5.  
  6. def buttonCallback(gpioNum):
  7.     if( gpioNum == button1_sensor_pin ):
  8.         print('button 1 gedrückt')
  9.     elif( gpioNum == button2_sensor_pin ):
  10.         print("button 2 gedrückt")
  11.  
  12.  
  13. GPIO.setmode( GPIO.BCM )
  14. GPIO.setup( button1_sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  15. GPIO.setup( button2_sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  16.  
  17. print ("linker buttons pin %d and %d"%(button1_sensor_pin,button2_sensor_pin))
  18. GPIO.add_event_detect(button1_sensor_pin, GPIO.RISING, callback=buttonCallback, bouncetime=500)
  19. GPIO.add_event_detect(button2_sensor_pin, GPIO.RISING, callback=buttonCallback, bouncetime=500)
  20.  
  21. print "Taste zum beenden drücken"
  22. try:
  23.     raw_input()
  24. except KeyboardInterrupt:
  25.     print " bye bye "
  26. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement