我有一个脚本来管理电源通过继电器与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下来或失败。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐