Advertisement
GregersBoye

GPIO-control

Nov 11th, 2020
1,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2.  
  3. # GPIO setup
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setwarnings(False)
  6. GPIO.setup(17,GPIO.OUT)
  7.  
  8. # Turn on/off LED based on user input
  9. try:
  10.     while True:
  11.         user_input = input("Turn LED On or Off with 1 or 0 (Ctrl-C to exit): ")
  12.  
  13.         if user_input == 1:
  14.             GPIO.output(17,GPIO.HIGH)
  15.             print("LED is on")
  16.         elif user_input == 0:
  17.             GPIO.output(17,GPIO.LOW)
  18.             print("LED is off")
  19.  
  20. except KeyboardInterrupt:
  21.    GPIO.cleanup()
  22.    print("")
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement