from time import sleep
from machine import Pin, PWM, RTC, ADC
pwm = PWM(Pin(1))
pwm.freq(50)
VRX = ADC(Pin(27))
VRY = ADC(Pin(26))
SW = Pin(0,Pin.IN, Pin.PULL_UP)
rtc=RTC()
rtc.datetime((2024, 4, 12, 10, 20, 0, 0, 0))
itc = rtc.datetime()
print(itc)
def open_boom():
for position in range(1000,9000,50):
pwm.duty_u16(position)
sleep(0.01)
def close_boom():
for position in range(9000,1000,-50):
pwm.duty_u16(position)
sleep(0.01)
while True:
switch=SW.value()
xAxis = VRX.read_u16()
yAxis = VRY.read_u16()
if(yAxis> 32759):
# print("Up")
itc = rtc.datetime()
print("Gate Opened at ", itc[4], ":", itc[5], ":", itc[6])
open_boom()
sleep(0.1)
if(yAxis==0):
print("Gate Closed at ", itc[4], ":", itc[5], ":", itc[6])
close_boom()
sleep(0.1)
sleep(0.1)