Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. ledPin = 38       # define ledPin
  5. buttonPin = 40    # define buttonPin
  6.  
  7.  
  8. def setup():
  9.     GPIO.setmode(GPIO.BOARD)
  10.     GPIO.setup(ledPin, GPIO.OUT)
  11.     GPIO.setup(buttonPin, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  12.    
  13.    
  14. def loop():
  15.     while True:
  16.         if GPIO.input(buttonPin)==GPIO.LOW:
  17.             for x in range(5):
  18.                 GPIO.output(ledPin,GPIO.HIGH)
  19.                 time.sleep(0.3)
  20.                 GPIO.output(ledPin,GPIO.LOW)
  21.                 time.sleep(0.3)
  22.  
  23.    
  24. def destroy():
  25.     GPIO.cleanup()
  26.    
  27.  
  28. if __name__ == '__main__':
  29.     setup()
  30.     try:
  31.         loop()
  32.     except KeyboardInterrupt:
  33.         destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement