Advertisement
Happy99

relay shit

Dec 2nd, 2020 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. ##################################################
  2. #   CHANNEL     RPI pin     wiringPi    BCM
  3. #   CH1         29          P21         5          
  4. #   CH2         31          P22         6
  5. #   CH3         33          P23         13
  6. #   CH4         36          P27         16
  7. #   CH5         35          P24         19
  8. #   CH6         38          P28         20
  9. #   CH7         40          P29         21
  10. #   CH8         37          P25         26
  11. ##################################################
  12. #!/usr/bin/python
  13. # -*- coding:utf-8 -*-
  14. import RPi.GPIO as GPIO
  15. import time
  16.  
  17. try:
  18.     RelayChannel = [5,6,13,16,19,20,21,26]
  19.     #RelayState = [0,0,0,0,0,0,0,0]
  20.  
  21.     GPIO.setwarnings(False)
  22.     GPIO.setmode(GPIO.BCM)
  23.  
  24.     GPIO.setup(RelayChannel, GPIO.OUT, initial=GPIO.HIGH)
  25.  
  26.     print("Setup The Relay Module is [success]")
  27.  
  28.     def OpenRelay(channel):
  29.         GPIO.output(RelayChannel[channel], GPIO.LOW)
  30.         print("Channel ", channel, " open")
  31.  
  32.     def CloseRelay(channel):
  33.         GPIO.output(RelayChannel[channel], GPIO.HIGH)
  34.         print("Channel ", channel, " close")
  35.  
  36.     def ToggleRelay(channel):
  37.         if GPIO.input(RelayChannel[channel]) == 0:
  38.             GPIO.output(RelayChannel[channel], GPIO.HIGH)
  39.             print("Channel ", channel, " close")
  40.         else:
  41.             GPIO.output(RelayChannel[channel], GPIO.LOW)
  42.             print("Channel ", channel, " open")
  43.  
  44.     while True:
  45.         #OpenRelay(1)
  46.         ToggleRelay(1)
  47.         time.sleep(0.5)
  48.         #CloseRelay(1)
  49.         time.sleep(2)
  50.  
  51.  
  52. except:
  53.     print("exception")
  54.     GPIO.cleanup()
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement