print("\nMiniproject")
print("Created By : ASYRAAF_NAZMI_FIRDAUS")
print("Date: 24/5/2024\n")
#Import libraries/module
from machine import Pin, PWM
from utime import sleep
import servo1_library, servo2_library, ultrasonic1_library, ultrasonic2_library
#Pin declaration
trig1 = 5
echo1 = 18
trig2 = 14
echo2 = 27
servo_pin1 = 32
servo_pin2 = 33
#Parameter declaration
#Create an OBJECT name for module with library
sensor1 = ultrasonic1_library.HCSR04(trigger_pin=trig1, echo_pin=echo1)
sensor2 = ultrasonic2_library.HCSR04(trigger_pin=trig2, echo_pin=echo2)
entrance_gate = servo1_library.Servo(pin=servo_pin1)
exit_gate = servo2_library.Servo(pin=servo_pin2)
#main program
while True:
distance_in_cm1 = sensor1.distance_cm()
distance_in_cm2 = sensor2.distance_cm()
print("The distance for Entrance is", distance_in_cm1, "cm")
print("The distance for Exit is", distance_in_cm2, "cm")
# Entrance gate control
if distance_in_cm1 < 100: # Ultrasonic sensor logic for entrance
entrance_gate.move(angle=90) #Open the entrance gate
sleep(3) #Wait for 3 seconds to allow the car to pass
entrance_gate.move(angle=0) # Close the entrance gate
# Exit gate control
if distance_in_cm2 < 100: # Ultrasonic sensor logic for exit
exit_gate.move(angle=0) # Open the exit gate
sleep(3) # Wait for 3 seconds
exit_gate.move(angle=180) # Close the exit gate
sleep(1)