import time
time.sleep(0.8) # Wait for USB to become ready
print("Hello, Pi Pico! at Walmart")
from Buzzer import *
from LightStrip import *
from Displays import *
from Button import *
class DigitalPriceDisplay:
LOW_STOCK_THRESHOLD = 20 # threshold for stock warnings
def __init__(self):
self.buzzer = PassiveBuzzer(pin=19, name="Buzz")
self.lightstrip = LightStrip(pin=20, name="Lights")
self.display = LCDDisplay(sda=0, scl=1)
self.leftbutton = Button(pin=2, name='left', handler=self)
self.rightbutton = Button(pin=6, name='right', handler=self)
self.redbutton = Button(pin=11, name='red', handler=self)
self.myproducts = []
self.index = 0
self.help_active = False
self.addProducts()
self.showInfo()
def addProducts(self):
product1 = PackagedProduct('1234', 'Oatmeal', 'Organic Oatmeal', 100, 'GM', 2.49)
product2 = PackagedProduct('5678', 'Cereal', 'Cheerios', 10, 'Kelloggs', 4.49)
product3 = PackagedProduct('8363', 'PastaPenne', 'Barilla', 150, 'PG', 1.99)
product4 = PackagedProduct('B3O', 'Sprite24', 'Can Sodas', 30, 'Coca-Cola', 9.99)
product5 = PackagedProduct('B1W', 'PureLife30', 'Spring Water', 50, 'Nestle', 4.99)
product6 = PackagedProduct('B4U', 'OreoChoco', 'Oreo Cookies', 0, 'Nabisco', 15.99)
self.myproducts.extend([product1, product2, product3, product4, product5, product6])
def showInfo(self):
current = self.myproducts[self.index]
self.display.clear()
self.display._lcd.move_to(0, 0)
self.display._lcd.putstr(current.line1())
self.display._lcd.move_to(0, 1)
self.display._lcd.putstr(current.line2())
if current.stock == 0:
self.lightstrip.setColor((255, 0, 0)) # 🔴 red
elif current.stock <= self.LOW_STOCK_THRESHOLD:
self.lightstrip.setColor((255, 255, 0)) # 🟡 yellow
else:
self.lightstrip.setColor((0, 255, 0)) # 🟢 green
def feedback(self):
# Turn on the light (full white for visibility)
self.lightstrip.setBrightness(1.0)
self.lightstrip.on()
# Play buzzer tone for longer so it can be heard
self.buzzer.play(DO)
time.sleep(0.08)
self.buzzer.stop()
# Turn off the light after feedback
self.lightstrip.off()
def previousProduct(self):
if self.index > 0:
self.index -= 1
self.showInfo()
def nextProduct(self):
if self.index < len(self.myproducts) - 1:
self.index += 1
self.showInfo()
def buttonPressed(self, name):
self.feedback()
if name == 'left':
self.previousProduct()
elif name == 'right':
self.nextProduct()
elif name == 'red':
# toggle help alert
self.help_active = not self.help_active
if self.help_active:
self.startHelpAlert()
else:
self.stopHelpAlert()
def buttonReleased(self, name):
pass
def startHelpAlert(self):
"""Show help alert instantly."""
self.display.clear()
self.display._lcd.move_to(0, 0)
self.display._lcd.putstr("HELP!"[:16])
self.display._lcd.move_to(0, 1)
self.display._lcd.putstr("Assistance!"[:16])
def updateHelpAlert(self):
"""Blinking help alert cycle."""
if not self.help_active:
return
self.lightstrip.setColor((255, 0, 0))
self.buzzer.play(DO)
time.sleep(0.2)
self.buzzer.stop()
self.lightstrip.off()
time.sleep(0.2)
def stopHelpAlert(self):
self.help_active = False
self.lightstrip.off()
self.buzzer.stop()
self.showInfo()
# Product classes
class Product:
def __init__(self, sku, name, description, stock):
self.sku = sku
self.name = name
self.description = description
self.stock = stock
class BulkProduct(Product):
def __init__(self, sku, name, description, stock, manufacturer, msrp):
super().__init__(sku, name, description, stock)
self.manufacturer = manufacturer
self.msrp = msrp
def line1(self):
return f"{self.name} ${self.msrp:.2f}"
def line2(self):
return f"{self.description}"
class PackagedProduct(Product):
def __init__(self, sku, name, description, stock, manufacturer, price):
super().__init__(sku, name, description, stock)
self.manufacturer = manufacturer
self.price = price
def line1(self):
return f"{self.name} ${self.price:.2f}"
def line2(self):
return f"{self.description}"
# MAIN LOOP
if __name__ == "__main__":
mydisplay = DigitalPriceDisplay()
while True:
if mydisplay.help_active:
mydisplay.updateHelpAlert()
time.sleep(0.08)