from machine import Pin,PWM
import time
#Configuracion de pines
#Motor c/PWM (Output)
sMotor = PWM(Pin(27), freq=10000)
#Push de control (Input)
btn_subir = Pin(14, Pin.IN,Pin.PULL_UP)
btn_bajar = Pin(12,Pin.IN,Pin.PULL_UP)
# Valores de Duty Cycle 1 a 1023 de 1% a 99%
NIVELES_DUTY = [0, 102, 205, 307, 409, 512, 614, 716, 818, 921, 1023]
NivelActualPWM = 0
hubo_cambio = True
PWMAct = 0
def implementarPWMaMotor():
PWMAct = NIVELES_DUTY[NivelActualPWM]
sMotor.duty(PWMAct)
print("El Cycle Duty del PWM es: ", NivelActualPWM*10, "%")
print("",PWMAct)
while True:
if hubo_cambio == True:
implementarPWMaMotor()
hubo_cambio = False
elif btn_subir.value()==0 and NivelActualPWM <= 100:
NivelActualPWM += 1
hubo_cambio = True
time.sleep(0.2)
elif btn_bajar.value()==0 and NivelActualPWM > 0:
NivelActualPWM -= 1
hubo_cambio = True
time.sleep(0.2)
if NivelActualPWM > 110:
print("Llego a su Maximo")