Advertisement
Guest User

Script for relay toggling.

a guest
Feb 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. #!/usr/bin/python
  2. import RPi.GPIO as GPIO
  3. import pinsetup
  4.  
  5. ##  Setting up GPIO  ##
  6. pinnum = 26
  7. pinsetup.setup_pin1()
  8.  
  9. ## Decraring variables  ##
  10. r1state = None
  11.  
  12. # Getting current state of pin #
  13. print("Reading state...")
  14. r1state = GPIO.input(pinnum)
  15. print("Done")
  16.  
  17. # Main #
  18. if r1state == 0:
  19.     GPIO.output(pinnum, GPIO.HIGH)
  20.     print("Relay on")
  21.  
  22. if r1state == 1:
  23.     GPIO.output(pinnum, GPIO.LOW)
  24.     print("Relay off")
  25.     GPIO.cleanup()
  26.     print("Cleaned up!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement