I have 1 input button PIN 18 and 2 outputs PIN 12 and 16, when the input is HIGH, I would like the outputs to be activated and deactivate when input is LOW. I have attempted to use
if (GPIO.input(18)==True):
GPIO.output(16, False)
GPIO.output(12, False)
However, the outputs are only activated if the input is already HIGH before I run the program and it doesn't reactivate when I release the button and press it again. This is a snippet of my code right now
class Controller(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "Controller")
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0,weight=1)
menubar = tk.Menu(container)
moremenu = tk.Menu(menubar, tearoff=0)
moremenu.add_command(label="Contact Info",
command=lambda:self.show_frame(ContactPage))
moremenu.add_command(label="Exit", command=exitmenu)
menubar.add_cascade(label="More", font=MENU_FONT ,menu=moremenu)
menubar.add_cascade(label=" ", state="disabled")
explorer= tk.Menu(menubar, tearoff=0)
explorer.add_command(label="Manual Ventilator Ctrl",
command=lambda:self.show_frame(ManualCtrl))
explorer.add_command(label="Battery Fault Bypass",
command=lambda:self.show_frame(BatteryBypass))
explorer.add_command(label="Fault History",
command=lambda:self.show_frame(Faulthist))
explorer.add_command(label="Manual Battery Charging",
command=lambda:self.show_frame(Manualcharge))
menubar.add_cascade(label="Explorer", font=MENU_FONT, menu=explorer)
menubar.add_cascade(label=" ", state="disabled")
syssetupmenu= tk.Menu(menubar, tearoff=0)
setup= tk.Menu(menubar, tearoff=0)
setup.add_command(label="Clock Setup",
command=lambda:self.show_frame(Clocksetup))
setup.add_cascade(label="System Setup", menu=syssetupmenu)
setup.add_command(label="Factory Default",
command=lambda:self.show_frame(Factorydef))
syssetupmenu.add_command(label="Timer Setting",
command=lambda:self.show_frame(Timerset))
syssetupmenu.add_command(label="Latch Setting",
command=lambda:self.show_frame(Latchset))
syssetupmenu.add_command(label="Change User Password",
command=lambda:self.show_frame(Changeuserpw))
syssetupmenu.add_command(label="Change Access Password",
command=lambda:self.show_frame(Changeaccesspw))
syssetupmenu.add_command(label="Change Lockout Password",
command=lambda:self.show_frame(Changeadminpw))
syssetupmenu.add_command(label="Battery Display Calibration",
command=lambda:self.show_frame(Batterydisp))
syssetupmenu.add_command(label="Daily Auto Charging",
command=lambda:self.show_frame(Autocharg))
syssetupmenu.add_command(label="Fault Record Reset",
command=lambda:self.show_frame(Faultrec))
syssetupmenu.add_command(label="Diagnostic Records",
command=lambda:self.show_frame(Diag))
syssetupmenu.add_command(label="Battery Fault Setpoints",
command=lambda:self.show_frame(Batterysetpts))
menubar.add_cascade(label="Setup", font=MENU_FONT ,menu=setup)
tk.Tk.config(self, menu=menubar)
self.frames = {}
for F in (DefaultScreen, ContactPage, ManualCtrl,BatteryBypass, Faulthist, Manualcharge,
Clocksetup,Timerset,Latchset,Changeuserpw,Changeaccesspw,Changeadminpw,
Batterydisp,Autocharg,Faultrec,Diag,Batterysetpts,Factorydef):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(DefaultScreen)
def show_frame(self,cont):
frame = self.frames[cont]
frame.tkraise()
if (GPIO.input(18)==True):
GPIO.output(16, False)
GPIO.output(12, False)
I would really appreciate any help right now, an alternative method would be appreciated as well. Thank you so much :)