print("Project: Reverse Parking System for TOYOTA")
print("Developed by: HANNAN")
print("Date: 25/3/3035")
#Import library/module
from machine import Pin , PWM
import sensor_library #library sensor
import OLED_LIB #oled screen library
from time import sleep
#Pin Declaration
TRIG = Pin(14, Pin.IN)
ECHO = Pin(25, Pin.IN)
red_led = Pin(18, Pin.OUT)
buzzer = PWM (Pin(4, Pin.OUT))
SCL_Pin = Pin (22 , Pin.OUT)
SDA_pin = Pin (21 , Pin.OUT)
OLED_Pin = SoftI2C (SCL_Pin , SDA_pin)
#object Declaration (Only needed when the sensor has library)
#object_name = library_name.class_name(......)
reverse_sensor = sensor_library.HCSR04(trigger_pin =TRIG, echo_pin =ECHO, echo_timeout_us=500*2*30)
display = OLED_LIB.SoftI2C (width = 128, height = 64, i2c = OLED_Pin)
#Parameter Declaration
#Main Program
while True:
measure_distance = reverse_sensor. distance_cm() #Output is in number
print("Distance from wall is", measure_distance, "cm")
#Display distance on screen for user's view
display.fill(0)
display.text("Distance from wall :" ,3 , 0, 1)
display.text(str(measure_distance), 10,10,1) #conver value to string for measure_distance
display.text ("cm" , 80,10,1)
display.show()
#Conditions to check distance car from wall while reverse
if measure_distance <= 50:
red_led.on()
buzzer.init(freq=5000 , duty=1023)
elif 50 < measure_distance <=100:
red_led.on()
buzzer.init(freq=2500 , duty=512)
sleep(0.25)
red_led.off()
sleep(0.25)
else:
red_led.off()
buzzer.init(freq=800 , duty=0)
sleep(0.25)
#system delay
sleep(0.5)