tdrobotica

Proyecto Servomotor

Dec 30th, 2021 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #importar librerias
  2. from machine import Pin, PWM
  3. from time import sleep
  4.  
  5. #codigo de programa
  6. def main():
  7.     #configuracion de pulso de servo
  8.     pin_servo = Pin(25)
  9.     pul_servo = PWM(pin_servo)
  10.     pul_servo.freq(50)
  11.     #variables de incremento y de duty inicial
  12.     step = 2
  13.     duty = 18
  14.     #ciclo infinito de programa
  15.     while(1):
  16.         #evaluar limites para 0° y 180°
  17.         if(duty<18):
  18.             step = 2
  19.         elif(duty>115):#sirve para enlazar varias condiciones
  20.             step = -2
  21.         #incrementar duty y fijar
  22.         duty = duty + step
  23.         pul_servo.duty(duty)
  24.         #tiempo entre variacion
  25.         sleep(0.2)
  26.         print(pul_servo.duty())
  27.  
  28. if __name__ == "__main__":
  29.     main()
Add Comment
Please, Sign In to add comment