当继电器失效时,覆盆子pi切换到直流电?

时间:2017-03-29 14:44:22

标签: python raspberry-pi relay

我有一个脚本通过Relay通过Rpi管理电源,但我想知道如何在继电器或覆盆子出现故障或关闭时切换直接连接?

from tkinter import *
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)      


GPIO.setup(7, GPIO.IN)
GPIO.setup(8, GPIO.IN)
GPIO.setup(25, GPIO.OUT)

GPIO.output(25, False)

ch1 = GPIO.input(7)
ch2 = GPIO.input(8)


def exit():
    root.destroy()
    GPIO.cleanup()
    sys.exit()

def save():
    runit()
    labelshow()

def runit():
    global cl1
    global cl2
     global go
     ch1 = GPIO.input(7)
     ch2 = GPIO.input(8)
     go = False

     if ch1 == True:
         cl1 = 0
     if ch1 == False:
         cl1 = 1
         go = True

     if ch2 == True:
         cl2 = 0
     if ch2 == False:
         cl2 = 1
         go = True

     root.after(10, runit)


def labelshow():
    if cl1 == 1:
        label1.pack()
        label1.update()
        # root.after(1000)
        # label1.pack_forget()
    root.after(20, labelshow)              

root = Tk()
root.geometry('600x600+600+50')

label1 = Label(root, text='hello')
but1 = Button(root, text='save', command=save).pack()
but2 = Button(root, text='exit', command=exit).pack()


root.mainloop()

以上代码工作正常我需要在继电器,引脚或rpi发生故障或故障时切换到直流电。

0 个答案:

没有答案