Krheigh
Posts: 17
Joined: Sat May 20, 2017 8:48 pm

panic button

Sun Jan 14, 2018 1:06 am

hi im building an aquaruim computer GUI of a rpi2. got everything working exept a panic button that shall turn off everything. im new to this so my coding skills is... :P i need to turn of gpio 33, 34, 35, 36, 37, 38 ,40 on a single click

error
panic button pressed
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1545, in __call__
return self.func(*args)
File "LATControllerpanik.py", line 115, in panicON
if GPIO.input(33, 34, 35, 36, 37, 38, 40,) :
TypeError: function takes exactly 1 argument (7 given)

Code: Select all

#!/usr/bin/python2
import Tkinter
from Tkinter import *
import tkFont
import RPi.GPIO as GPIO

root=Tkinter.Tk()
root.title('Lazy Ass Tank Controller')
root.geometry('394x190-1430-757')
root.configure(background='red')
var=Tkinter.StringVar()
label=Tkinter.Label(root,font=('Roman, Sans',35),fg='black',bg='yellow',wraplength=800, textvariable = var)
label.grid(row=3, column=0, columnspan=10, sticky=W)
tsensor='/sys/bus/w1/devices/28-03168bc0c2ff/w1_slave'

def traw():
    f=open(tsensor,'r')
    lines=f.readlines()
    f.close()
    return lines
def readtemp():
    lines=traw()
    while lines[0].strip()[-3:]!='YES':
        time.sleep(0.2)
        lines=traw()
    tout=lines[1].find('t=')
    if tout!=-1:
        tstr=lines[1].strip()[tout+2:]
        tc = round(float(tstr)/1000,1)
        space=('C  F')
        tf=round(tc*9.0/5.0+32.0,1)
        return tc,space,tf


def on_alarm(top_level_window):
        global var
        var.set(readtemp())
        top_level_window.after(2000,on_alarm,top_level_window)


root.after(1000, on_alarm, root)

GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
GPIO.output(40, GPIO.LOW)
GPIO.setup(38, GPIO.OUT)
GPIO.output(38, GPIO.LOW)
GPIO.setup(37, GPIO.OUT)
GPIO.output(37, GPIO.LOW)
GPIO.setup(36, GPIO.OUT)
GPIO.output(36, GPIO.LOW)
GPIO.setup(35, GPIO.OUT)
GPIO.output(35, GPIO.LOW)
GPIO.setup(33, GPIO.OUT)
GPIO.output(33, GPIO.LOW)

myFont = tkFont.Font(family = 'Roman, Sans', size = 12, weight = 'bold')

def skimmerON():
	print("Skimmer button pressed")
	if GPIO.input(40) :
 		GPIO.output(40,GPIO.LOW)
		skimmerButton["text"] = "Skimmer ON"
	else:
		GPIO.output(40,GPIO.HIGH)
                skimmerButton["text"] = "Skimmer OFF"

def streamerON():
	print("Streamer button pressed")
	if GPIO.input(38) :
 		GPIO.output(38,GPIO.LOW)
		streamerButton["text"] = "Streamer ON"
	else:
		GPIO.output(38,GPIO.HIGH)
                streamerButton["text"] = "Streamer OFF"

def heaterON():
	print("Heater button pressed")
	if GPIO.input(37) :
 		GPIO.output(37,GPIO.LOW)
		heaterButton["text"] = "Heater ON"
	else:
		GPIO.output(37,GPIO.HIGH)
                heaterButton["text"] = "Heater OFF"

def pumpON():
	print("pump button pressed")
	if GPIO.input(36) :
 		GPIO.output(36,GPIO.LOW)
		pumpButton["text"] = "Pump ON"
	else:
		GPIO.output(36,GPIO.HIGH)
                pumpButton["text"] = "Pump OFF"

def uvcON():
	print("uvc button pressed")
	if GPIO.input(35) :
 		GPIO.output(35,GPIO.LOW)
		uvcButton["text"] = "UVC ON"
	else:
		GPIO.output(35,GPIO.HIGH)
                uvcButton["text"] = "UVC OFF"
                
def mixpumpON():
	print("mix button pressed")
	if GPIO.input(33) :
 		GPIO.output(33,GPIO.LOW)
		mixButton["text"] = "Mixpump ON"
	else:
		GPIO.output(33,GPIO.HIGH)
                mixButton["text"] = "Mixpump OFF"     
                
def panicON():
	print("mix button pressed")
	if GPIO.input(33, 34, 35, 36, 37, 38, 40,) :
 		GPIO.output(33, 33, 34, 35, 36, 37, 38, 40,GPIO.LOW)
		panicButton["text"] = "ALL ON"
	else:
		GPIO.output(33, 33, 34, 35, 36, 37, 38, 40,GPIO.HIGH)
                panicButton["text"] = "ALL OFF"                          

def exitProgram():
	print("Exit Button pressed")
        GPIO.cleanup()
	root.quit()	


streamerButton = Button(root, text = "Streamer", font = myFont, command = streamerON, height = 1, width =12)
streamerButton.grid(row=0, column=2, sticky=E)

heaterButton = Button(root, text = "Heater", font = myFont, command = heaterON, height = 1, width =12)
heaterButton.grid(row=1, column=2, sticky=E)

skimmerButton = Button(root, text = "Skimmer", font = myFont, command = skimmerON, height = 1, width =12)
skimmerButton.grid(row=0, sticky=W)

pumpButton = Button(root, text = "Returnpump", font = myFont, command = pumpON, height = 1, width =12)
pumpButton.grid(row=1, sticky=W)

uvcButton = Button(root, text = "UVC", font = myFont, command = uvcON, height = 1, width =12)
uvcButton.grid(row=2, sticky=W)

mixButton = Button(root, text = "Mixpump", font = myFont, command = mixpumpON, height = 1, width =12)
mixButton.grid(row=2, column=2, sticky=E)

panicButton = Button(root, text = "PANIC", font = myFont, command = panicON, height = 4, width =5)
panicButton.grid(row=0, column=1, rowspan=3)

exitButton  = Button(root, text = "Exit", font = myFont, command = exitProgram, height =1 , width =35) 
exitButton.grid(row=5, column=0, columnspan=3, sticky=W)


root.mainloop()


/code]

pcmanbob
Posts: 4347
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: panic button

Sun Jan 14, 2018 10:17 am

You are getting the error be cause you have specified 7 gpio in the line " if GPIO.input(33, 34, 35, 36, 37, 38, 40,) :"

you need to do each gpio individually with an "or" between them of you want any one being on to result in a true.

some thing like this

if GPIO.input(33) or GPIO.input(34) or GPIO.input(35) etc......

there are other ways of doing it I will leave you to research them.

some examples
if any( [cond1 == 'val1', cond2 == 'val2', cond3 == 'val3', cond4 == 'val4'] ):

rules = [test == 'wrong',
test == 'test2',
test == 'test3',
test == 'test4']:
if all(rules):
# Do something.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: panic button

Sun Jan 14, 2018 4:00 pm

Code: Select all

for i in [1,2,3,4,5]:
	print i
should give you a clue.

Dave.
Apple say... Monkey do !!

Return to “Python”

Who is online

Users browsing this forum: MrYsLab and 12 guests