from machine import Pin, I2C
from time import sleep
from hcsr04 import HCSR04
import i2c_lcd
# Ultrasonic sensor setup
sensor = HCSR04(trigger_pin=3, echo_pin=2)
# LED for parking full
led = Pin(14, Pin.OUT)
# LCD setup
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
lcd = i2c_lcd.I2cLcd(i2c, 0x27, 2, 16)
# Parking slots
total_slots = 5
available_slots = 5
lcd.clear()
lcd.putstr("Smart Parking")
sleep(2)
while True:
distance = sensor.distance_cm()
if distance < 10: # Car detected
if available_slots > 0:
available_slots -= 1
lcd.clear()
lcd.putstr("Car Parked")
sleep(2)
else:
lcd.clear()
lcd.putstr("Parking Full")
led.on()
sleep(2)
lcd.clear()
lcd.putstr("Slots Left:")
lcd.move_to(0,1)
lcd.putstr(str(available_slots))
if available_slots > 0:
led.off()
sleep(2)