Advertisement
KRITSADA

Rpi Event From 4 input key

Apr 24th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3. GPIO.setmode(GPIO.BCM)
  4. GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_UP)
  5. GPIO.setup(18,GPIO.IN,pull_up_down=GPIO.PUD_UP)
  6. GPIO.setup(6,GPIO.IN,pull_up_down=GPIO.PUD_UP)
  7. GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_UP)
  8. GPIO.setup(5,GPIO.OUT)
  9. def prints(CH) :
  10.     print ('Button', CH, 'Pressed')
  11. try :
  12.     GPIO.add_event_detect(17,GPIO.RISING,callback=prints,bouncetime=300)
  13.     GPIO.add_event_detect(18,GPIO.RISING,callback=prints,bouncetime=300)
  14.     GPIO.add_event_detect(6,GPIO.RISING,callback=prints,bouncetime=300)
  15.     GPIO.add_event_detect(23,GPIO.RISING,callback=prints,bouncetime=300)
  16.     while True :
  17.         GPIO.output(5,1)
  18.         time.sleep(0.2)
  19.         GPIO.output(5,0)
  20.         time.sleep(0.2)
  21. finally :
  22.     GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement