from machine import Pin,I2C
from time import sleep
from pico_i2c_lcd import I2cLcd
i2c=I2C(1,sda=Pin(26),scl=Pin(27))
i2c_add=i2c.scan()
lcd=I2cLcd(i2c,i2c_add[0],2,16)
lcd.backlight_on()
lcd.clear()
entry_pir=Pin(0,Pin.IN)
exit_pir=Pin(1,Pin.IN)
max_count_led=Pin(19,Pin.OUT)
button1=Pin(7,Pin.IN,Pin.PULL_DOWN)
button2=Pin(8,Pin.IN,Pin.PULL_DOWN)
led=Pin(2,Pin.OUT)
max_theatre_count=20
theatre_count=0
entry_num=0
exit_num=0
def lcd_count_panel(number):
lcd.move_to(7,1)
lcd.putstr(str(number))
def max_count_indicator():
max_count_led.value(1)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Theatre Full")
lcd.move_to(0,1)
lcd.putstr("Count:")
lcd_count_panel(theatre_count)
def entry_exit_indicator():
led.value(1)
sleep(0.5)
led.value(0)
while True:
if entry_pir.value()==1:
entry_num+=1
entry_exit_indicator()
if theatre_count < max_theatre_count:
theatre_count+=1
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Entry Done!")
elif exit_pir.value()==1:
exit_num+=1
entry_exit_indicator()
if theatre_count>0:
theatre_count-=1
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Exit Done")
elif button1.value()==1:
lcd.clear()
lcd.move_to(0,0)
if theatre_count>0:
lcd.putstr("Theatre Presence")
else:
lcd.putstr("Theatre Empty")
lcd.move_to(0,1)
lcd.putstr("Count:")
lcd_count_panel(theatre_count)
elif button2.value()==1:
lcd.clear()
if theatre_count<max_theatre_count:
lcd.move_to(0,0)
lcd.putstr("Seats Available")
else:
lcd.move_to(0,0)
lcd.putstr("Theatre Full")
lcd.move_to(0,1)
lcd.putstr("Count:")
lcd_count_panel(theatre_count)
elif theatre_count==max_theatre_count:
max_count_indicator()
else:
max_count_led.value(0)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Cinema Theatre ")
sleep(0.5)