import time
time.sleep(1) # Wait for USB to become ready
print("Hello, Pi Pico W!")
# Import necessary modules
from Buzzer import PassiveBuzzer
from LightStrip import LightStrip
from Displays import LCDDisplay
from Button import Button
from modelclasses import PackagedProduct, BulkProduct
# Define the color constants for the lights
BLUE = (0, 0, 255)
YELLOW = (255, 200, 0)
RED = ( 255, 0, 0)
# Main class for the digital price display system
class DigitalPriceDisplay:
def __init__(self):
self.buzzer = PassiveBuzzer(pin=15, name='Buzzer') # create an instance of buzzer
self.lightstrip = LightStrip (pin=2, name='Lights', numleds=8) # create an instance of lightstrip
self.display = LCDDisplay(sda=0, scl=1) # create an instance of display
self.leftbutton = Button(pin=16, name='left',handler=self) # left button
self.rightbutton =Button(pin=17, name='right', handler=self) # right button
self.myproducts = [] # create an empty list called myproducts
self.addProducts() # add products to the list
self.index = 0 # initialize index to 0
# Create and add products to the list
def addProducts(self):
product1 = PackagedProduct('1234','Oatmeal','Quaker', 100,'GM',2.49)
product2 = PackagedProduct ('1235','Cereal','Honeynut_Cheerios', 55,'GM',4.49)
product3 = PackagedProduct ('1236','Cereal','_The_Farmland___', 30,'Cascadian Farm',6.49)
product4 = PackagedProduct ('1237','Grits','_Bob_Red_Mill_', 10, 'Bob Red Mill', 13.44)
product5 = BulkProduct ('1111','Cornmeal_25', 'Nature_Valley_', 60, 25, '11/30/2026')
self.myproducts.append(product1)
self.myproducts.append(product2)
self.myproducts.append(product3)
self.myproducts.append(product4)
self.myproducts.append(product5)
def update_stock_indicator(self):
product = self.myproducts[self.index]
stock = product.stock
if stock > 50:
self.lightstrip.setColor(BLUE)
elif stock > 20:
self.lightstrip.setColor(YELLOW)
else:
self.lightstrip.setColor(RED)
self.lightstrip.blink(RED, duration=1)
def showInfo(self): # Display product info on LCD
self.display.clear()
product = self.myproducts[self.index]
self.display.showText(product.line1(), 0)
self.display.showText(product.line2(), 1)
self.update_stock_indicator()
def previousProduct(self): # Navigate the previous product
if self.index > 0:
self.index -= 1
self.showInfo()
self.buzzer.beep(tone=500, duration=500)
def nextProduct(self): # Navigate the next product
if self.index < len(self.myproducts) - 1:
self.index += 1
self.showInfo()
self.buzzer.beep(tone=1000, duration=500)
def buttonPressed(self,name): # Hadle button press
if name =='right':
self.nextProduct()
elif name == 'left':
self.previousProduct()
def buttonReleased(self,name): # Optional : handle button release
pass
if __name__=='__main__': # Run the program
mydisplay = DigitalPriceDisplay()
mydisplay.showInfo()
print('\nSimulating button presses...')
time.sleep(1)
mydisplay.buttonPressed('left')
time.sleep(1)
mydisplay.buttonPressed('left')
time.sleep(1)