from machine import UART, Pin
import utime
from time import sleep_ms
import _thread
blue = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
led = Pin(25, Pin.OUT)
Led_Iny_1 = Pin(14, Pin.OUT)
Led_Iny_2 = Pin(15, Pin.OUT)
Led_Iny_3 = Pin(16, Pin.OUT)
Led_Iny_4 = Pin(17, Pin.OUT)
T_act = 0
T_des = 0
#Iny_1 = 0;
#Iny_2 = 1;
#Iny_3 = 1;
#Iny_4 = 1;
#Start = 0;
#RPM = 0;
Data_List = [0,0,0]
Data_List_comando = [0,0,0]
msg = [0,0,0,0,0,0,0]
dato = [b'']
dato_str = []
dato_str_cln = []
bloqueo = _thread.allocate_lock()
while blue.any() == 0:
print(dato)
utime.sleep_ms(300)
def APK_com():
global Iny_1
global Iny_2
global Iny_3
global Iny_4
global Start
global RPM
utime.sleep_ms(300)
while True:
with bloqueo:
T_act = 7+(RPM/30)
T_des = 125-((29*RPM)/15)
if Start == 1:
if Iny_1 == 1:
Led_Iny_1.value(1)
else:
Led_Iny_1.value(0)
if Iny_2 == 1:
Led_Iny_2.value(1)
else:
Led_Iny_2.value(0)
if Iny_3 == 1:
Led_Iny_3.value(1)
else:
Led_Iny_3.value(0)
if Iny_4 == 1:
Led_Iny_4.value(1)
else:
Led_Iny_4.value(0)
utime.sleep_ms(int(T_act))
Led_Iny_1.value(0)
Led_Iny_2.value(0)
Led_Iny_3.value(0)
Led_Iny_4.value(0)
utime.sleep_ms(int(T_des))
else:
Led_Iny_1.value(0)
Led_Iny_2.value(0)
Led_Iny_3.value(0)
Led_Iny_4.value(0)
print(Iny_1)
print(Iny_2)
print(Iny_3)
print(Iny_4)
print(Start)
print(RPM)
"""
Iny_1 = dato[0]
while True:
if blue.any()>0:
dato = blue.read(256)
print(dato)
Iny_1 = dato[0]
Iny_2 = dato[1]
Iny_3 = dato[2]
Iny_4 = dato[3]
Start = dato[4]
RPM = dato[5]
if Iny_1==1:
Led_Iny_1.value(1)
else:
Led_Iny_1.value(0)
if Iny_2==1:
Led_Iny_2.value(1)
else:
Led_Iny_2.value(0)
if Iny_3==1:
Led_Iny_3.value(1)
else:
Led_Iny_3.value(0)
if Iny_4==1:
Led_Iny_4.value(1)
else:
Led_Iny_4.value(0)
"""
#for i in range(0,2):
#led_on = msg[i]
#i = i+1
#if msg[0]==0:
#led.value(1)
#blue.write("Led encendido\r\n")
# elif msg[0]==1:
#led.value(0)
#blue.write("Led apagado\r\n")
#utime.sleep_ms(3000)
"""def nucleo2():
global Iny_1
while True:
with bloqueo:
if Iny_1==1:
Led_Iny_1.value(1)
else:
Led_Iny_1.value(0)
time.sleep(1)"""
#_thread.start_new_thread(nucleo2, ())
_thread.start_new_thread(APK_com, ())
while True:
global Iny_1
global Iny_2
global Iny_3
global Iny_4
global Start
global RPM
if blue.any()>0:
dato = blue.read(256)
with bloqueo:
Iny_1 = dato[0]
Iny_2 = dato[1]
Iny_3 = dato[2]
Iny_4 = dato[3]
Start = dato[4]
RPM = dato[5]
"""
with bloqueo:
if Iny_1==1:
Led_Iny_1.value(1)
else:
Led_Iny_1.value(0)
utime.sleep_ms(1000)
while True:
global Iny_1
if Iny_1==1:
Led_Iny_1.value(1)
else:
Led_Iny_1.value(0)
#print(msg)
#print(msg[0])
#print(msg[1])
#print(msg[2])
#print(msg[3])
#print(msg[4])
#print(msg[5])
# dato_str=dato.decode('utf-8')
# dato_str_cln=dato_str.strip(0)
# if blue.any() > 0:
# dato = blue.read(256)
# print(dato)
# for i in range(0,1):
# Data_List_comando [i] = dato[int(i)]
# i = i+1
# print(Data_List_comando)
# tiempo = msg[5]
#print(tiempo)
"""