print("Revers Parking System")
print("Date: 2/4/2026")
#Import Libraries/modules
from machine import Pin, SoftI2C
import Oled_library
import ultrasonic_library
from utime import sleep
from mmachine import Pin, PWM
#Pin Declaration
oled_pin = SoftI2C(scl = Pin(22) , sda = Pin(21) )
TRIG = Pin(12)
ECHO = Pin(14)
red = Pin(17, Pin.OUT)
yellow = Pin(16, Pin.OUT)
green = Pin(18, Pin.OUT)
buzz = PWM(Pin(25, Pin.OUT))
#Object Declaration
#Required ONLY when external library is used
#ObjectName = LibraryName.ClassName (........)
OLED = Oled_library.SSD1306_I2C(width = 128 , height = 64 , i2c = oled_pin)
ULTRA = ultrasonic_library.HCSR04(trigger_pin = TRIG, echo_pin = ECHO)
#Main Program
while True:
#Measure nearby object
distance_in_cm = OLED.distance_cm()
#Display on terminal
print("Objek terdekat adalah dalam : ", distance_in_cm, "cm")
print("-----------------------------------------------------")
if distance_in_cm >= 200:
OLED.fill(1) #1 for white, 0 for black
OLED.text("LAB 410", 10, 5, col=0)
asta.show()
yellow.off()
green.off()
#LED Indicator
for i in range (f):
red.on()
sleep(0.3)
red.off()
sleep(0.3)
#Buzzer Indicator
buzz.init(freq=1000, duty=0)
elif 100<= distance_in_cm < 200:
OLED.fill(1) #1 for white, 0 for black
OLED.text("FIREFIRE!!!", 10, 20, col=0)
OLED.text("PEOPLE NEARBY", 10, 35, col=0)
OLED.text("IOT LAB", 10, 45, col=0)
OLED.show()
red.off()
green.off()
#LED Indicator
for i in range (f):
yellow.on()
sleep(0.3)
yellow.off()
sleep(0.3)
#Buzzer Indicator
buzz.init(freq=1000, duty=50)
else:
OLED.fill(1) #1 for white, 0 for black
OLED.text("WELCOME TO", 10, 20, col=0)
OLED.text("IOT LAB", 10, 30, col=0)
OLED.text("HAVE FUN", 8, 40, col=0)
OLED.show()
red.off()
yellow.off()
#LED Indicator
for i in range (5):
green.on()
sleep(0.3)
green.off()
sleep(0.3)
#Buzzer Indicator
buzz.init(freq=850, duty=120)
sleep(1) #system delay