import time
from machine import Pin,ADC,PWM,RTC
servo = PWM(Pin(0,Pin.OUT))
servo.freq(50)
x_axis = ADC(26)
y_axis = ADC(27)
gate_pos = 0
rtc = RTC()
rtc.datetime((2024,4,12,5,10,37,30,0))
butt = Pin(5,Pin.IN,Pin.PULL_UP)
def move_servo():
for i in range(1000,9000):
servo.duty_u16(i)
time.sleep(0.001)
def close_servo():
for i in range(9000,1000,-1):
servo.duty_u16(i)
time.sleep(0.001)
while True:
if butt.value() == 0 and gate_pos==0:
tm = rtc.datetime()
print("Gate Opened AT {0}:{1}:{2}".format(tm[4],tm[5],tm[6]))
move_servo()
time.sleep(2)
gate_pos=1
if gate_pos==1 and butt.value() == 0:
tm = rtc.datetime()
print("Gate Closed AT {0}:{1}:{2}".format(tm[4],tm[5],tm[6]))
close_servo()
gate_pos=0