import time
time.sleep(0.1) # Wait for USB to become ready
from machine import Pin,PWM
ledb=Pin(18,Pin.OUT)
ledr=Pin(19,Pin.OUT)
ledo=Pin(27,Pin.OUT)
ledp=Pin(26,Pin.OUT)
buzzer=PWM(Pin(20))
buzzer.freq(600)
vol=20000
button=Pin(17,Pin.IN)
servo1=PWM(Pin(21))
servo1.freq(50)
servo2=PWM(Pin(22))
servo2.freq(50)
#buzzer.duty_u16(vol)
def servo1_angle(angle):
duty = int((angle / 180 * 2 + 0.5) / 20 * 65535)
servo1.duty_u16(duty)
def servo2_angle(angle):
duty = int((angle / 180 * 2 + 0.5) / 20 * 65535)
servo2.duty_u16(duty)
def tell_time(k,l,step3,step4):
k=int(k/6)
l=int(l/6)
h=3
if step3==-6:
l=60-l
if step4==-6:
k=60-k
if k<10 :
time=["0",k,":",l]
h=4
if l<10 :
time=[k,":","0",l]
h=4
if k<10 and l<10:
time=["0",k,":","0",l]
h=5
time_str = f"{k:02}:{l:02}"
print(time_str)
i=0
j=0
step1=6
step2=6
servo2_angle(j)
while True:
if step1==-6 and i==0:
j=j+step2
servo2_angle(j)
if i>=180:
step1=-6
if j>=180:
step2=-6
if i<=0:
step1=6
if j<=0:
step2=6
if step1==6:
ledr.off()
ledb.on()
if step1==-6:
ledb.off()
ledr.on()
if step2==6:
ledo.off()
ledp.on()
if step2==-6:
ledp.off()
ledo.on()
servo1_angle(i)
if button.value()==1:
tell_time(j,i,step1,step2)
time.sleep(1)
i=i+step1