# Importar librerías
import time
import machine
import sys
from machine import Pin # Librería de GPIO del RPI PICO
# Definición de Funciones
def dectobin(num):
textb=""
ii=128
for a in range(0,8,1):
if num & ii ==0:
textb=textb+"0"
else:
textb=textb+"1"
ii=ii>>1
return textb
def salp(num,lista):
for pins in lista:
Pin(pins,Pin.OUT)
ii=128
for pins in lista:
if ((num & ii) !=0):
Pin(pins,Pin.OUT).value(1)
else:
Pin(pins,Pin.OUT).value(0)
ii=ii>>1
def main():
boton1 = None
boton2 = None
boton3 = None
boton4 = None
# Configuración de hardware
print("Motores")
if sys.platform == "esp32":
leds1 = [21, 19, 18, 5] # Pines para ESP32
leds2 = [17, 16, 4, 2] # Pines para ESP32
boton1 = machine.Pin(33, machine.Pin.IN, machine.Pin.PULL_UP) # Botón 1 - GPIO 32
boton2 = machine.Pin(32, machine.Pin.IN, machine.Pin.PULL_UP)
boton3 = machine.Pin(35, machine.Pin.IN, machine.Pin.PULL_UP)
boton4 = machine.Pin(34, machine.Pin.IN, machine.Pin.PULL_UP)
elif sys.platform == "rp2":
leds1 = [2, 3, 4, 5] # Pines para Raspberry Pi Pico
leds2 = [6, 7, 8, 9]
boton1 = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP) # Botón en GPIO 1 con resistencia pull-up
boton2 = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP)
boton3 = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_UP)
boton4 = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_UP)
# Inicialización de Variables
cont1 = 1 # Empieza con 00000001 en binario
cont2 = 1
# Bucle infinito
while True:
if boton1.value() == 0:
time.sleep(0.1)
if boton2.value() == 0:
cont1 <<= 1
if cont1 > 128:
cont1 = 8
else:
cont1 >>= 1
if cont1 < 8:
cont1 = 128
if boton3.value() == 0:
time.sleep(0.1)
if boton4.value() == 0:
cont2 <<= 1
if cont2 > 128:
cont2 = 8
else:
cont2 >>= 1
if cont2 < 8:
cont2 = 128
salp(cont1, leds1)
salp(cont2, leds2)
time.sleep(0.2) # Pequeña pausa para evitar múltiples activaciones
if __name__ == '__main__':
main()
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
bargraph1:A1
bargraph1:A2
bargraph1:A3
bargraph1:A4
bargraph1:A5
bargraph1:A6
bargraph1:A7
bargraph1:A8
bargraph1:A9
bargraph1:A10
bargraph1:C1
bargraph1:C2
bargraph1:C3
bargraph1:C4
bargraph1:C5
bargraph1:C6
bargraph1:C7
bargraph1:C8
bargraph1:C9
bargraph1:C10
sw2:1a
sw2:2a
sw2:3a
sw2:4a
sw2:5a
sw2:6a
sw2:7a
sw2:8a
sw2:8b
sw2:7b
sw2:6b
sw2:5b
sw2:4b
sw2:3b
sw2:2b
sw2:1b