from time import sleep_ms,ticks_ms,ticks_diff
from machine import Pin
import random
sleep_ms(500)
print("sin error")
#BOTON QUE INICIA TODO
BOTON0=Pin(0,Pin.IN)
#el boton cero inicia el contador y por ende el juego, tiene
#que estar encima de los displays para que el jugador pueda activarlo
#sin ese boton nada funciona
#PULSO QUE ACTIVA SONIDO DE PERDER
B0MBA=Pin(21, Pin.OUT)
#COMO YA NO QUEDAN MAS PINES EN LA PLACA, ESTO VA A MANDAR UN PULSO
#DE ACTIVACION A LA SEGUNDA PLAQUETA CUANDO SE GANE EL NIVEL DOS
nivel_tres_inicio=Pin(28, Pin.OUT)
#ENTRADAS DE CABLES
boton1=Pin(1, Pin.IN)
boton2=Pin(2, Pin.IN)
boton3=Pin(3, Pin.IN)
boton4=Pin(4, Pin.IN)
#para que funcione y que se tengan que desconectar los cables, en vez de activarse por 1 que lo
#hagan por cero: if v1==0:
# if v(2,3,4)==0: y asi para que se deba conectar el cable
#SALIDAS PARA EL LED LVL1 Y EL CONTADOR DEL ARDUINO
led1 = Pin(27, Pin.OUT)
salidaARD1=Pin(26, Pin.OUT) #va al arduino, es el azul
salidaARD2=Pin(22, Pin.OUT) #va al arduino, es el azul a la derecha, cada pulso saca 3 a T
#salidaARD1 manda un pulso que vale un segundo
#salidaARD2 manda un pulso que vale dos segundos
#activada_placa_dos=Pin(16,Pin.IN)
#LUCES QUE INDICAN EL NIVEL EN VERDE
luznivel1=Pin(20,Pin.OUT)
t=180 #tiempo
lvl1=0 #variable bloqueo/desbloqueo para nivel 1
lvl2=0 #variable bloqueo/desbloqueo para nivel 2
#FUNCION DE LVL 1
def parpadeo(): #funcion del nivel 1[cables]
global t #es para que la variable t sea igual en todo el codigo
#Acevedo dijo que es de maricon pero yo programador no soy
t0 = ticks_ms()
while boton2.value() == 1 or boton3.value() == 1 or boton4.value() == 1:
led1.toggle()
sleep_ms(300)
tahora = ticks_ms()
if ticks_diff(tahora, t0) >= 1000:
t = max(0, t - 3) # Descuenta 3 cada 1 segundo
t0 = tahora
print(t)
salidaARD2.value(1)
sleep_ms(50)
salidaARD2.value(0)
led1.value(0)
#----------------------------------------------------------------
#----------------------------------------------------------------
#ENTRADAS CLAUDIO DICE:
botonc1=Pin(5,Pin.IN)
botonc2=Pin(6,Pin.IN)
botonc3=Pin(7,Pin.IN)
botonc4=Pin(8,Pin.IN)
botonc5=Pin(9,Pin.IN)
botonInicioClaudio=Pin(15, Pin.IN)#si esto no se toca
#el nivel no empieza pero
#corre el tiempo igual
#SALIDAS CLAUDIO DICE:
ledc1=Pin(10,Pin.OUT)
ledc2=Pin(11,Pin.OUT)
ledc3=Pin(12,Pin.OUT)
ledc4=Pin(13,Pin.OUT)
ledc5=Pin(14,Pin.OUT)
# Listas para la serie de colores
leds = [ledc1, ledc2, ledc3, ledc4, ledc5]
botones = [botonc1, botonc2, botonc3, botonc4, botonc5]
colores = [0, 1, 2, 3, 4]
secuencia = []
nivel = 1
jugando = True
nivel_maximo = 10
correcta = True
def nivel2():
global t, lvl2
secuencia = []
nivel = 1
jugando = True
nivel_maximo = 10
tiempo_ultimo_descuento = ticks_ms()
while jugando:
if t <= 0:
jugando = False
break
if nivel > nivel_maximo:
lvl2 = 1
for led in leds:
led.value(1)
sleep_ms(2000)
for led in leds:
led.value(0)
jugando = False
break
print("Tiempo:", t)
#AGREGO NUEVO COLOR
nuevo = random.choice(colores)
secuencia.append(nuevo)
# MUESTRO LA SERIE DE LEDS
for indice in secuencia:
leds[indice].value(1)
sleep_ms(500)
leds[indice].value(0)
sleep_ms(500)
entrada_usuario = []
while len(entrada_usuario) < len(secuencia):
for i in range(5):
if botones[i].value() == 1:
leds[i].value(1)
sleep_ms(200)
leds[i].value(0)
entrada_usuario.append(i)
while botones[i].value() == 1:
pass
sleep_ms(100)
# Descuento de tiempo
if ticks_diff(ticks_ms(), tiempo_ultimo_descuento) >= 1000:
t -= 1
if t < 0:
t = 0
tiempo_ultimo_descuento = ticks_ms()
print("T:", t)
if t == 0:
jugando = False
break
if entrada_usuario == secuencia:
print("Correcto!")
nivel += 1
sleep_ms(1000)
else:
print("Error!")
t -= 10
if t < 0:
t = 0
salidaARD1.value(1)
sleep_ms(100)
salidaARD1.value(0)
for led in leds:
led.value(1)
sleep_ms(1000)
for led in leds:
led.value(0)
print("Fin del nivel 2, tiempo restante:", t)
#INICIO PROGRAMA PRINCIPAL:
while True:
activada_placa_dos=0
while t>0 and activada_placa_dos==0:
inicio=BOTON0.value()#inicio general del juego
#inicio nivel 1
if inicio==1 and lvl1==0: #inicia nivel 1
while t>0:
luznivel1.value(1)
t=t-1
sleep_ms(1000)
print(t)
salidaARD1.value(1)#inicia pulso
sleep_ms(50)#por cada pulso, el arduino descuenta 1
salidaARD1.value(0)#termina pulso para el arduino
v1= boton1.value()
if v1 == 1:
led1.value(1)
print("avance al lvl 2")
luznivel1.value(0)
if t>0:
print("nivel dos iniciado")
nivel2()
nivel_tres_inicio.value(1)
sleep_ms(500)
nivel_tres_inicio.value(0) #aca deja de mandar el pulso
else:
led1.value(0)
v2=boton2.value()
v3=boton3.value()
v4=boton4.value()
if v2==1 or v3==1 or v4==1:
if t>=3:
t=t-3
print(t)
parpadeo()
if t==0:
print("T es:",t,"segundos, perdiste gordo LoL")
sleep_ms(50)
B0MBA.value(1) #FIN NIVEL 1