Advertisement
KRITSADA

Rpi Event and call back function

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