from machine import Pin, I2C
import time
import keypad
import lcd1602
# Initialize I2C for LCD
i2c = I2C(0, scl=Pin(5), sda=Pin(4)) # Using GPIO 5 for SCL, GPIO 4 for SDA
lcd = lcd1602.Lcd(i2c)
# Food items and their prices
food_items = {
"1": ("Idli", 30),
"2": ("Dosa", 50),
"3": ("Vada", 20),
"4": ("Sambar Rice", 60),
"5": ("Curd Rice", 40),
"6": ("Biryani", 120),
"7": ("Pongal", 35),
"8": ("Uthappam", 55),
}
# Initialize keypad (row pins and column pins)
rows = [Pin(8, Pin.IN, Pin.PULL_UP), Pin(9, Pin.IN, Pin.PULL_UP),
Pin(10, Pin.IN, Pin.PULL_UP), Pin(11, Pin.IN, Pin.PULL_UP)]
cols = [Pin(12, Pin.OUT), Pin(13, Pin.OUT), Pin(14, Pin.OUT), Pin(15, Pin.OUT)]
# Set columns to high initially
for col in cols:
col.value(1)
# Dictionary to store the quantity of items selected
quantities = {item[0]: 0 for item in food_items.values()}
# Function to update the display with selected food items and total
def update_display():
lcd.clear()
lcd.putstr("Tamil Food Shop\n")
for idx, (key, (item, qty)) in enumerate(quantities.items()):
if qty > 0:
lcd.putstr(f"{item}: {qty}x ₹{food_items[key][1]}\n")
total = sum(food_items[key][1] * qty for key, qty in quantities.items())
lcd.putstr(f"Total: ₹{total}")
# Function to read from the keypad
def read_keypad():
for row_num, row in enumerate(rows):
row.value(0) # Set row to low to scan
for col_num, col in enumerate(cols):
if row.value() == 0: # If a key is pressed
key = str(row_num * 4 + col_num + 1)
time.sleep(0.1) # Debounce time
return key
row.value(1) # Reset row to high
return None # No key pressed
# Main loop
while True:
key = read_keypad() # Read key from keypad
if key is not None:
if key in food_items:
# Increment the quantity for the selected food item
item_name, price = food_items[key]
quantities[item_name] += 1
update_display() # Update the LCD display
elif key == "9": # You can add a reset or clear functionality
# Reset the quantities
quantities = {item[0]: 0 for item in food_items.values()}
update_display()
time.sleep(0.1) # Small delay for the keypad scan