Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from machine import Pin, PWM
- from time import sleep
- #este metodo
- def set_vel_motor_M1(vel):
- #configurar pines para motor M1
- ain_1 = PWM(Pin(12))
- ain_2 = PWM(Pin(13))
- #Fijar las frecuencias a 60Hz
- ain_1.freq(80)
- ain_2.freq(80)
- #fijar la velocidad
- if(vel>0):
- ain_1.duty(vel*10)
- ain_2.duty(0)
- elif(vel<0):#permite verificar varias condiciones al incluir una o más verificaciones elif después de su declaración if inicial.
- vel = -vel
- ain_1.duty(0)
- ain_2.duty(vel*10)
- else:
- ain_1.duty(0)
- ain_2.duty(0)
- def main():
- vel = 250
- step = 10
- while(1):
- set_vel_motor_M1(vel)
- vel += step
- sleep(2)
- if(vel>100 or vel<-100):
- step = -step
- vel += step
- print(vel)
- pass
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement