import machine
import utime
from lcd1602 import LCD
lcd = LCD()
menu_items = [
("Burger", "RM5.99"),
("Pizza", "RM8.99"),
("Pasta", "RM6.99"),
("Salad", "RM4.99"),
("Drink", "RM1.99")
]
button_pin = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_DOWN)
current_index = 0
button_pressed = False
debounce_time = 200
last_button_press = 0
def display_menu_item():
for i in range(len(menu_items)):
item, price = menu_items[i]
lcd.clear()
lcd.write(0, 0, item)
lcd.write(0, 1, price)
time.sleep(1)
def display_splash_screen():
lcd.clear()
lcd.write(0, 0, "Push PB to")
lcd.write(0, 1, "explore menu")
time.sleep(3)
lcd.clear()
def handle_menu_navigation(pin):
global current_index, button_pressed, last_button_press
current_time = utime.ticks_ms()
if utime.ticks_diff(current_time, last_button_press) < debounce_time:
return
last_button_press = current_time
button_pressed = not button_pressed
if button_pressed:
current_index = (current_index + 1) % len(menu_items)
display_menu_item()
button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler=handle_menu_navigation)
while True:
display_splash_screen()
if button_pressed:
display_menu_item()