from machine import Pin,ADC
from servo import Servo
import time

Servo_Azul = Servo(pin=27)
Servo_Rojo = Servo(pin=26)
Servo_Amarillo = Servo(pin=22)
Pote = ADC(28)
'''
def mapeo(x):
    return (x*180)/100
'''

def mapeo(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min


def mover_servo(r):
    move.servo(r)
    utime.sleep_ms(10)


while True:
    cant_rojo = int(input("Ingrese la cantidad de pigmento Rojo: "))
    cant_azul = int(input("Ingrese la cantidad de pigmento Azul: "))
    cant_amarillo = int(input("Ingrese la cantidad de pigmento Amarillo: "))
    cant_mezcla = float(input("Ingrese el peso total de la mezcla: "))
    
    if (cant_rojo > 0 and cant_rojo <100) and (cant_azul > 0 and cant_azul <100) and (cant_amarillo > 0 and cant_amarillo <100):
        Rojo = mapeo(cant_rojo, 0, 65535, 0, 180)
        Azul = mapeo(cant_azul, 0, 65535, 0, 180)
        Amarillo = mapeo(cant_amarillo, 0, 65535, 0, 180)

        
        if Pote <= 3103: #Si esta en 2,5V
            Servo_Rojo.mover(Rojo)
            Servo_Azul.mover(Azul)
            Servo_Amarillo.mover(Amarillo)
        else:
            Servo_Rojo.mover(0)
            Servo_Azul.mover(0)
            Servo_Amarillo.mover(0)
    else:
        print("Valor/es mal ingresados")
        break


    utime.sleep_ms(0.1)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT