import time
from machine import Pin, PWM
# Pines
stby = Pin(13, Pin.OUT)
ain1 = Pin(10, Pin.OUT)
ain2 = Pin(11, Pin.OUT)
pwma = PWM(Pin(12))
bin1 = Pin(6, Pin.OUT)
bin2 = Pin(7, Pin.OUT)
pwmb = PWM(Pin(8))
bot = Pin(15, Pin.IN, Pin.PULL_UP)
# Configurar frecuencia del PWM
pwma.freq(1000)
pwmb.freq(1000)
encendido = False
while True:
if bot.value() == 0: # Si se presiona el botón
encendido = not encendido # Cambia de encendido a apagado y viceversa
if encendido:
stby.value(1)
ain1.value(1)
ain2.value(0)
pwma.duty_u16(65535) # 100% velocidad
bin1.value(1)
bin2.value(0)
pwmb.duty_u16(65535) # 100% velocidad
else:
stby.value(0)
pwma.duty_u16(0)
pwmb.duty_u16(0)
time.sleep(0.3) # Espera para no detectar múltiples clicsLoading
pi-pico-w
pi-pico-w