Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from machine import Pin, ADC,PWM
- from time import sleep
- def set_vel_motor_M1(vel):
- #configurar pines para motor M1
- ain_1 = PWM(Pin(12))
- ain_2 = PWM(Pin(13))
- #Fijar las frecuencias
- ain_1.freq(100)
- ain_2.freq(100)
- #fijar la velocidad
- if(vel>0):
- ain_1.duty(vel)
- ain_2.duty(0)
- else:
- ain_1.duty(0)
- ain_2.duty(0)
- def main():
- #definir al pin 32 como entrada analoga
- pot = ADC(Pin(32))
- pot.atten(ADC.ATTN_11DB)#establece atenuacion de entrada de 11dB
- pot.width(ADC.WIDTH_9BIT)#establece valores de retorno de 9 bits
- pot.read()
- while(1):
- pot_value = int(pot.read())
- vel = int(pot_value)
- #tiempo de espera
- sleep(0.2)
- set_vel_motor_M1(vel)
- print(vel)
- #ruta de ejecucion
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement