from machine import Pin,PWM
from time import sleep 

push1=Pin(12,Pin.IN,Pin.PULL_UP)
dir1=Pin(27,Pin.OUT)
dir2=Pin(26,Pin.OUT)
motor=PWM(Pin(18),freq=1000)

while(1):
  if(push1.value()==0):
     sleep(0.02)
     motor.duty(800)
     dir1.on()
     dir2.off()
     sleep(5)
     motor.duty(1023)
     dir1.on()
     dir2.off()
     sleep(5)
     sleep(0.1)
     motor.duty(800)
     dir1.off()
     dir2.on()
     sleep(5)
     motor.duty(1023)
     dir1.off()
     dir2.on()
     sleep(5)
     
   
  else:
    motor.duty(0)
    dir1.off()
    dir2.off()