## Declaracion de librerias
from machine import Pin
import time
## Configuracion de puertos GPIO
pinEnabled = Pin(13, Pin.OUT, value = 0)
pinStep = Pin(15, Pin.OUT)
pinDirection = Pin(14, Pin.OUT, value = 1)
boton_direccion = Pin(18, machine.Pin.IN, machine.Pin.PULL_DOWN)
boton_velocidad = Pin(17, machine.Pin.IN, machine.Pin.PULL_DOWN)
boton_pasos = Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)
#pinEnabled.on() #Habilitar el Enabled del TB6600
#stepsPerRevolution = 200 #200 pasos por revolucion (1.8° por paso)
velocidad = (5,10,30,100,500) #Retraso entre paso
bandera = 1 #Bandera para cambio de direccion de giro
contador_velocidad = 0
## Programa principal
while True:
if boton_direccion.value() == 1 and bandera == 0:
time.sleep_ms(100) #Anti rebote
print('Sentido a favor de manecillas')
pinDirection.on()
bandera = 1
elif boton_direccion.value() == 1 and bandera == 1:
time.sleep_ms(100)
print('Sentido en contra de las manecillas')
pinDirection.off()
bandera = 0
if boton_velocidad.value() == 1:
time.sleep_ms(100)
while boton_velocidad.value() == 1:
pass
time.sleep_ms(100)
contador_velocidad += 1
time.sleep_ms(100)
D = "Cambio de velocidad = " + str(velocidad[contador_velocidad]) # Arreglo a presentar
print(D)
if contador_velocidad > 4:
contador_velocidad = 0
if boton_pasos.value() == 1:
pinStep.on()
time.sleep_ms(100)
pinStep.off()
time.sleep_ms(100)