from machine import Pin, I2C
from time import sleep
from i2c_lcd import I2cLcd
# === I2C LCD Setup ===
I2C_ADDR = 0x27 # May be 0x3F on some modules
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
# === Pin Assignments ===
ir_pins = [32, 33, 25, 26]
led_pins = [13, 12, 14, 27]
# === GPIO Setup ===
ir_sensors = [Pin(pin, Pin.IN) for pin in ir_pins]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
# === Initial LCD Display ===
lcd.clear()
lcd.putstr("P1-P4: Free")
def update_display(status):
lcd.clear()
line = "P1:{} P2:{}\nP3:{} P4:{}"
lcd.putstr(line.format(
"Full" if status[0] else "Free",
"Full" if status[1] else "Free",
"Full" if status[2] else "Free",
"Full" if status[3] else "Free"
))
while True:
slot_status = []
for i in range(4):
occupied = ir_sensors[i].value() == 0 # Assuming LOW when blocked
slot_status.append(occupied)
leds[i].value(occupied) # Turn on LED if occupied
update_display(slot_status)
sleep(0.5)