"""
PROYECTO: Relog de gym con display LCD I2C
PRESENTADO POR
-Angelina Figueroa Taborda
-Asdrubal Andres Velez Bohorquez
-Mauricio Muñoz Acosta
NOTAS: CONFIGURACION BOTONES(VERTICAL HACIA ABAJO):
-1er PULSADOR: Aumentar los minutos
-2do PULSADOR: Disminuir los minutos
-1er PULSADOR: Decrementar el valor
-2do PULSADOR: Aumentar el valor
-3er PULSADOR: set point
-4to PULSADOR: reset
"""
from machine import I2C, Pin
import pico_i2c_lcd
import utime
from esp32_gpio_lcd import GpioLcd
from utime import sleep_ms, ticks_ms
from time import sleep
# Configura el bus I2C
# Reemplaza 2 y 3 con los pines de SDA y SCL
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
#Declaracion botones
Boton4 = Pin(18,Pin.IN)
Boton5 = Pin(4,Pin.IN)
Boton = Pin(23,Pin.IN)
Boton1 = Pin(19,Pin.IN)
Boton2 = Pin(32,Pin.IN)
Boton3 = Pin(33,Pin.IN)
# La dirección I2C del LCD puede variar, este es un valor común.
lcd_address = 0x27
pac_abierto = [
0b01110,
0b10001,
0b10000,
0b10001,
0b01110,
0b00000,
0b00000,
0b00000]
pac_cerrado = [
0b01110,
0b10001,
0b10001,
0b10001,
0b10001,
0b01110,
0b00000,
0b00000]
lcd = pico_i2c_lcd.I2cLcd(i2c, lcd_address, 2, 16) # Asume un LCD de 2x16
lcd.custom_char(0, pac_abierto)
lcd.custom_char(1, pac_cerrado)
# Limpia el LCD
lcd.clear()
# Muestra texto
lcd.putstr("LABORATORIO 3")
utime.sleep(2) # Espera 2 segundos
lcd.clear()
lcd.putstr("RELOG GYM LCD")
# Espera y luego limpia la pantalla antes de finalizar, si es necesario
utime.sleep(2)
lcd.clear()
lcd.putchar(chr(1))
#Declaracion contadores y variables auxiliares
C=0
c=0
s=0
a=0
b=0
mi=0
anterior = 0
actual = 0
Boton.value(0)
contador=0
while True:
lcd.move_to(0, 0)
lcd.putstr("%2d" % (mi))
lcd.putstr(" :")
lcd.putstr("%5d" % (s))
c=c+1
actual=Boton.value()
r=Boton1.value()
x=Boton2.value()
v=Boton4.value()
z=Boton5.value()
if actual == 1 :
s=s+1
if r == 1 :
s=s-1
if z == 1 or s <= -1 :
mi=mi-1
if mi == 0 :
s=59
if s == -1 :
s=59
if s == 60 or v == 1 :
mi=mi+1
if s == 60 :
s=0
if mi == -1 :
mi=59
if mi == 60 :
mi=0
if Boton3.value() != 0 :
mi=0
s=0
if x==1 :
a=s
b=mi
s=0
y=0
ref=0
l=0
while (y == 0) :
y=Boton3.value()
if b == 0:
mi=0
lcd.move_to(0, 0)
lcd.putstr("%2d" % (mi))
lcd.putstr(" :")
lcd.putstr("%5d" % (s))
s=s+1
if s == a+1:
s=0
lcd.move_to(0, 0)
lcd.putstr("TIEMPO TERMINADO")
utime.sleep(2)
lcd.clear()
if y == 1 :
s=0
if b != 0 :
lcd.move_to(0, 0)
lcd.putstr("%2d" % (ref))
lcd.putstr(" :")
lcd.putstr("%5d" % (s))
s=s+1
y=Boton3.value()
if s == 60 :
s=0
ref+=1
if ref == b :
print(s)
if s == a+1:
s=0
ref = 0
lcd.move_to(0, 0)
lcd.putstr("TIEMPO TERMINADO")
utime.sleep(2)
lcd.clear()
if y == 1 :
s=0
ref=0