from machine import Pin,PWM import time #Two pins of the motor p0 = Pin(19,Pin.OUT) p1 = Pin(18,Pin.OUT) INA =PWM(p0,freq=10000, duty_u16=8192)#INA corresponds to IN+ INB =PWM(p1,freq=10000, duty_u16=8192)#INB corresponds to IN- button1 = Pin(16, Pin.IN, Pin.PULL_UP) count1 = 0 try: while True: btnVal1 = button1.value() # Reads the value of button 1 if(btnVal1 == 0): time.sleep(0.01) while(btnVal1 == 0): btnVal1 = button1.value() if(btnVal1 == 1): count1 = count1 + 1 print("comp1" , count1) val1 = count1 % 2 if(val1 == 1): INA.duty(0) #The range of duty cycle is 0-1023 INB.duty(700) else: INA.duty(0) INB.duty(0) except: INA.duty(0) INB.duty(0) INA.deinit() INB.deinit()