#
========================================== # - Programa para manejo RELE de control - # ------------------------------------------ # - J.C.G.P. - (c) Webtronika 2013 - # # Modificado el 22/08/2013 por SETA43 # ========================================== #!/usr/bin/python import sys import curses import time import RPi.GPIO as GPIO # --------------------------------------------------------------- # - Rutina de configuracion de puertos en GPIO ------------------ # --------------------------------------------------------------- def confiGPIO(param1): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) GPIO.setup(25, GPIO.OUT) return 0 # --------------------------------------------------------------- # ############################################################### # - PROGRAMA PRINCIPAL ------------------------------------------ # # Utiliza curses para visualizar salida a pantalla # # ############################################################### # --------------------------------------------------------------- stdscr = curses.initscr() curses.cbreak() curses.start_color() curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN) hsize = curses.COLS vsize = curses.LINES curses.curs_set(0) curses.noecho stdscr.border(0) stdscr.keypad(1) stdscr.nodelay(1) confiGPIO(0) try: stdscr.bkgd(curses.color_pair(1)) while True: # Rutina principal del programa char = stdscr.getch() time.sleep(.1) ### Hace que el sistema no se sature if (char == 81 or char == 113): # Tecla Q/q break if (char == 49): # Tecla 1 GPIO.output(23, True) if (char == 50): # Tecla 2 GPIO.output(23, False) if (char == 51): # Tecla 3 GPIO.output(24, True) if (char == 52): # Tecla 4 GPIO.output(24, False) if (char == 53): # Tecla 5 GPIO.output(25, True) if (char == 54): # Tecla 6 GPIO.output(25, False) else: stdscr.addstr(vsize/6, (hsize/2)-18,"Control de RELE via GPIO") stdscr.addstr((vsize/5)+2, (hsize/2)- 22,"[1] - Activa el RELE1") stdscr.addstr((vsize/5)+3, (hsize/2)- 22,"[2] - Desactiva el RELE1") stdscr.addstr((vsize/5)+5, (hsize/2)- 22,"[3] - Activa el RELE2") stdscr.addstr((vsize/5)+6, (hsize/2)- 22,"[4] - Desactiva el RELE2") stdscr.addstr((vsize/5)+8, (hsize/2)- 22,"[5] - Activa el RELE3") stdscr.addstr((vsize/5)+9, (hsize/2)- 22,"[6] - Desactiva el RELE3") stdscr.addstr(vsize-8, (hsize/2)- 18," Pulsa [Q] para salir") stdscr.refresh() finally: curses.nocbreak() stdscr.keypad(0) curses.echo() curses.endwin() |
#!/usr/bin/python import Tkinter import RPi.GPIO as GPIO def confiGPIO(param1): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) GPIO.setup(25, GPIO.OUT) return 0 def on1(): print "on1" GPIO.output(23, True) return def off1(): print "off1" GPIO.output(23, False) return def on2(): print "on2" GPIO.output(24, True) return def off2(): print "off2" GPIO.output(24, False) return def on3(): print "on3" GPIO.output(25, True) return def off3(): print "off3" GPIO.output(25, False) return confiGPIO(0) top = Tkinter.Tk() top.geometry("200x250") top.title("RELE_TK") #top.config(bg="blue") A = Tkinter.Button(top, text ="ON1 ", command = on1) B = Tkinter.Button(top, text ="OFF1", command = off1) C = Tkinter.Button(top, text ="ON2 ", command = on2) D = Tkinter.Button(top, text ="OFF2", command = off2) E = Tkinter.Button(top, text ="ON3 ", command = on3) F = Tkinter.Button(top, text ="OFF3", command = off3) Q = Tkinter.Button(top, text ="QUIT",fg="red", command = quit) A.pack() B.pack() C.pack() D.pack() E.pack() F.pack() Q.pack() top.mainloop() |