ScymnusRIP

RPI-GPIO-on-off

Jun 20th, 2022 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. from time import sleep
  3.  
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setwarnings(False)
  6.  
  7. Relay_PIN = 23
  8. GPIO.setup(Relay_PIN, GPIO.OUT)
  9.  
  10. print('[press ctrl+c to end the script]')
  11. try: # Main program loop
  12.     while True:
  13.         GPIO.output(Relay_PIN, GPIO.HIGH)
  14.         print('Normally opened pin is HIGH')
  15.         sleep(1) # Waitmode for 1 second
  16.         GPIO.output(Relay_PIN, GPIO.LOW)
  17.         print('Normally opened pin is LOW')
  18.         sleep(1) # Waitmode for 1 second
  19. # Scavenging work after the end of the program
  20. except KeyboardInterrupt:
  21.     print('Script end!')
  22. finally:
  23.     GPIO.cleanup()
  24.  
Add Comment
Please, Sign In to add comment