Advertisement
tdrobotica

Proyecto Motor DC Banco

Jan 12th, 2022
1,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. from machine import Pin, ADC,PWM
  2. from time import sleep
  3.  
  4. def set_vel_motor_M1(vel):
  5.     #configurar pines para motor M1
  6.     ain_1 = PWM(Pin(12))
  7.     ain_2 = PWM(Pin(13))
  8.     #Fijar las frecuencias
  9.     ain_1.freq(100)
  10.     ain_2.freq(100)
  11.     #fijar la velocidad
  12.     if(vel>0):
  13.         ain_1.duty(vel)
  14.         ain_2.duty(0)
  15.     else:
  16.         ain_1.duty(0)
  17.         ain_2.duty(0)
  18.  
  19. def main():
  20.     #definir al pin 32 como entrada analoga
  21.     pot = ADC(Pin(32))
  22.     pot.atten(ADC.ATTN_11DB)#establece atenuacion de entrada de 11dB
  23.     pot.width(ADC.WIDTH_9BIT)#establece valores de retorno de 9 bits
  24.     pot.read()
  25.     while(1):
  26.         pot_value = int(pot.read())
  27.         vel = int(pot_value)
  28.         #tiempo de espera
  29.         sleep(0.2)
  30.         set_vel_motor_M1(vel)
  31.         print(vel)
  32.  
  33. #ruta de ejecucion
  34. if __name__ == "__main__":
  35.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement