Matthew YongZoolier YTRadenoch Rioveroshat _
Published

Sustainable Retail Technology Project Grp1-C2

Designing a solution to improve the quality of life of staff in retail stores through dealing with low-level tasks and questions of patrons

BeginnerFull instructions provided127
Sustainable Retail Technology Project Grp1-C2

Things used in this project

Story

Read more

Code

Kiosk Code (M5Stack1)

MicroPython
Requires Angle and PIR Unit
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x000000)
pir_0 = unit.get(unit.PIR, unit.PORTA)
angle_0 = unit.get(unit.ANGLE, unit.PORTB)


data = None
angleunit = None
STOCK_STATUS = None
selected_item = None



greeting1 = M5TextBox(58, 72, "Good day, user!", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
bottomborder = M5Rect(0, 230, 320, 10, 0xFFFFFF, 0xFFFFFF)
topborder = M5Rect(0, 0, 320, 10, 0xFFFFFF, 0xFFFFFF)
greeting2 = M5TextBox(25, 124, "How can I help you today?", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
item1 = M5TextBox(18, 48, "AIRism Cotton T-Shirt (Blue)", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
item2 = M5TextBox(17, 77, "TYS Chinese O'Level Revisio", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
item3 = M5TextBox(18, 102, "Lychee-Flavoured Bak Wa", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
item4 = M5TextBox(18, 130, "Akko V3 Switch - Cream Blue", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
item5 = M5TextBox(18, 160, "Ang Bao (15pcs)", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
Price = M5TextBox(45, 72, "Price:      $40   ", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
Shelf = M5TextBox(28, 147, "Shelf:       Benedict", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
Stock = M5TextBox(44, 177, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label0 = M5TextBox(45, 203, "Map", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label2 = M5TextBox(218, 203, "Back", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
image1 = M5Img(0, 8, "res/default.jpg", True)
label1 = M5TextBox(82, 71, "Price:      $40   ", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label3 = M5TextBox(129, 182, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image0 = M5Img(99, -380, "res/default.jpg", True)


# Describe this function...
def item_info2():
  global data, STOCK_STATUS, angleunit, selected_item
  label0.show()
  while True:
    Stock.hide()
    Stock.setText(str(STOCK_STATUS))
    item1.show()
    item1.setPosition(25, 50)
    item2.hide()
    item3.hide()
    item4.hide()
    item5.hide()
    Price.setText('Price: $25')
    Price.show()
    Price.setPosition(25, 90)
    Shelf.setText('Shelf: A ')
    Shelf.show()
    Shelf.setPosition(25, 120)
    label2.show()
    label0.setText('Map')
    if btnA.isPressed():
      item1.hide()
      Price.hide()
      Shelf.hide()
      selected_item = 1
      wait(1)
      Toggle_map()
    if btnC.isPressed():
      Shelf.hide()
      item1.hide()
      Price.hide()
      selected_item = -2
      wait(1)
      Itemselection()
      selected_item = -1
    wait_ms(2)

# Describe this function...
def item_info3():
  global data, STOCK_STATUS, angleunit, selected_item
  label0.show()
  while True:
    Stock.hide()
    item1.hide()
    item2.show()
    item2.setPosition(25, 50)
    item3.hide()
    item4.hide()
    item5.hide()
    Price.setText('Price: $30')
    Price.show()
    Price.setPosition(25, 90)
    Shelf.setText('Shelf: B ')
    Shelf.show()
    Shelf.setPosition(25, 120)
    label2.show()
    label0.setText('Map')
    if btnA.isPressed():
      item2.hide()
      Price.hide()
      Shelf.hide()
      selected_item = 2
      wait(1)
      Toggle_map()
    if btnC.isPressed():
      Shelf.hide()
      item2.hide()
      Price.hide()
      selected_item = -2
      wait(1)
      Itemselection()
    wait_ms(2)

# Describe this function...
def startup():
  global data, STOCK_STATUS, angleunit, selected_item
  greeting1.hide()
  greeting2.hide()
  item1.hide()
  item2.hide()
  item3.hide()
  item4.hide()
  item5.hide()
  greeting1.hide()
  Shelf.hide()
  Price.hide()
  Stock.hide()
  image0.hide()

# Describe this function...
def Welcome_Page():
  global data, STOCK_STATUS, angleunit, selected_item
  while True:
    item1.hide()
    item2.hide()
    item3.hide()
    item4.hide()
    item5.hide()
    greeting1.hide()
    Price.hide()
    Shelf.hide()
    label0.hide()
    label2.hide()
    greeting2.hide()
    greeting1.hide()
    image0.changeImg("res/default.jpg")
    greeting1.show()
    if btnB.isPressed():
      showetemlist()
      Itemselection()
    wait_ms(2)

# Describe this function...
def Welcome_Page3():
  global data, STOCK_STATUS, angleunit, selected_item
  greeting1.hide()
  greeting1.hide()
  greeting1.hide()
  greeting1.hide()
  greeting1.hide()
  greeting1.hide()
  greeting1.hide()
  greeting1.hide()

# Describe this function...
def showetemlist():
  global data, STOCK_STATUS, angleunit, selected_item
  greeting2.hide()
  greeting1.hide()
  Shelf.hide()
  Price.hide()
  item1.show()
  item1.setPosition(25, 25)
  item2.show()
  item2.setPosition(25, 50)
  item3.show()
  item3.setPosition(25, 75)
  item4.show()
  item4.setPosition(25, 100)
  item5.show()
  item5.setPosition(25, 120)
  image0.hide()

# Describe this function...
def Itemselection():
  global data, STOCK_STATUS, angleunit, selected_item
  while True:
    image0.hide()
    label2.hide()
    label0.setText('Select')
    angleunit = int(((angle_0.read()) / 5.68))
    if angleunit <= 36:
      item1.setColor(0xffcc66)
      item1.setPosition(25, 25)
      item2.setColor(0xffffff)
      item2.setPosition(25, 50)
      item3.setColor(0xffffff)
      item3.setPosition(25, 75)
      item4.setColor(0xffffff)
      item4.setPosition(25, 100)
      item5.setColor(0xffffff)
      item5.setPosition(25, 120)
    if angleunit > 36 and angleunit <= 72:
      item1.setColor(0xffffff)
      item1.setPosition(25, 25)
      item2.setColor(0xffcc66)
      item2.setPosition(25, 50)
      item3.setColor(0xffffff)
      item3.setPosition(25, 75)
      item4.setColor(0xffffff)
      item4.setPosition(25, 100)
      item5.setColor(0xffffff)
      item5.setPosition(25, 120)
    if angleunit > 72 and angleunit <= 108:
      item1.setColor(0xffffff)
      item1.setPosition(25, 25)
      item2.setColor(0xffffff)
      item2.setPosition(25, 50)
      item3.setColor(0xffcc66)
      item3.setPosition(25, 75)
      item4.setColor(0xffffff)
      item4.setPosition(25, 100)
      item5.setColor(0xffffff)
      item5.setPosition(25, 120)
    if angleunit > 108 and angleunit <= 144:
      item1.setColor(0xffffff)
      item1.setPosition(25, 25)
      item2.setColor(0xffffff)
      item2.setPosition(25, 50)
      item3.setColor(0xffffff)
      item3.setPosition(25, 75)
      item4.setColor(0xffcc66)
      item4.setPosition(25, 100)
      item5.setColor(0xffffff)
      item5.setPosition(25, 120)
    if angleunit > 144:
      item1.setColor(0xffffff)
      item2.setColor(0xffffff)
      item3.setColor(0xffffff)
      item4.setColor(0xffffff)
      item5.setColor(0xffcc66)
      item5.setPosition(25, 120)
    if angleunit <= 36 and (btnA.isPressed()):
      selected_item = 1
      item_info2()
    if angleunit > 36 and angleunit <= 72 and (btnA.isPressed()):
      selected_item = 2
      item_info3()
    if angleunit > 72 and angleunit <= 108 and (btnA.isPressed()):
      selected_item = 3
      item_info4()
    if angleunit > 108 and angleunit <= 144 and (btnA.isPressed()):
      selected_item = 4
      item_info5()
    if angleunit > 144 and angleunit <= 360 and (btnA.isPressed()):
      selected_item = 5
      item_info6()
    wait_ms(2)

# Describe this function...
def Toggle_map():
  global data, STOCK_STATUS, angleunit, selected_item
  HideItems()
  label2.show()
  label0.hide()
  if selected_item == 1:
    image1.changeImg("res/ITEM1shirt.png")
    image1.show()
  if selected_item == 2:
    image1.changeImg("res/Item5real.png")
    image1.show()
  if selected_item == 3:
    image1.changeImg("res/Item4real.png")
    image1.show()
  if selected_item == 4:
    image1.changeImg("res/Item1real.png")
  if selected_item == 5:
    image1.changeImg("res/Item2real.png")
    image1.show()
  while True:
    if btnC.isPressed():
      wait(1)
      if selected_item == 1:
        label2.hide()
        label0.setText('Map')
        image1.hide()
        item_info2()
      if selected_item == 2:
        label2.hide()
        label0.setText('Map')
        image1.hide()
        item_info3()
      if selected_item == 3:
        label2.hide()
        label0.setText('Map')
        image1.hide()
        item_info4()
      if selected_item == 4:
        label2.hide()
        label0.setText('Map')
        image1.hide()
        item_info5()
      if selected_item == 5:
        label2.hide()
        label0.setText('Map')
        image1.hide()
        item_info6()
    wait_ms(2)

# Describe this function...
def HideItems():
  global data, STOCK_STATUS, angleunit, selected_item
  greeting1.hide()
  greeting2.hide()
  item1.hide()
  item2.hide()
  item3.hide()
  item4.hide()
  item5.hide()
  Price.hide()
  Shelf.hide()
  label0.hide()
  label2.hide()
  Stock.hide()
  greeting1.hide()

# Describe this function...
def item_info4():
  global data, STOCK_STATUS, angleunit, selected_item
  label0.show()
  while True:
    Stock.hide()
    item1.hide()
    item2.hide()
    item3.show()
    item3.setPosition(25, 50)
    item4.hide()
    item5.hide()
    Price.setText('Price: $15')
    Price.show()
    Price.setPosition(25, 90)
    Shelf.setText('Shelf: C')
    Shelf.show()
    Shelf.setPosition(25, 120)
    label2.show()
    label0.setText('Map')
    if btnA.isPressed():
      item3.hide()
      Price.hide()
      Shelf.hide()
      selected_item = 3
      wait(1)
      Toggle_map()
    if btnC.isPressed():
      Shelf.hide()
      item3.hide()
      Price.hide()
      selected_item = -3
      wait(1)
      Itemselection()
    wait_ms(2)

# Describe this function...
def item_info5():
  global data, STOCK_STATUS, angleunit, selected_item
  label0.show()
  while True:
    Stock.hide()
    item1.hide()
    item2.hide()
    item3.hide()
    item4.show()
    item4.setPosition(25, 50)
    item5.hide()
    Price.setText('Price: $30')
    Price.show()
    Price.setPosition(25, 90)
    Shelf.setText('Shelf: D')
    Shelf.show()
    Shelf.setPosition(25, 120)
    label2.show()
    label0.setText('Map')
    if btnA.isPressed():
      item4.hide()
      Price.hide()
      Shelf.hide()
      selected_item = 4
      wait(1)
      Toggle_map()
    if btnC.isPressed():
      Shelf.hide()
      item4.hide()
      Price.hide()
      selected_item = -4
      wait(1)
      Itemselection()
    wait_ms(2)

# Describe this function...
def item_info6():
  global data, STOCK_STATUS, angleunit, selected_item
  label0.show()
  while True:
    Stock.hide()
    item1.hide()
    item2.hide()
    item3.hide()
    item4.hide()
    item5.show()
    item5.setPosition(25, 50)
    Price.setText('Price: $10')
    Price.show()
    Price.setPosition(25, 90)
    Shelf.setText('Shelf: E')
    Shelf.show()
    Shelf.setPosition(25, 120)
    label2.show()
    label0.setText('Map')
    if btnA.isPressed():
      item5.hide()
      Price.hide()
      Shelf.hide()
      selected_item = 5
      wait(1)
      Toggle_map()
    if btnC.isPressed():
      HideItems()
      selected_item = -5
      wait(1)
      Itemselection()
    wait_ms(2)



label3.hide()
bottomborder.show()
topborder.show()
startup()
HideItems()
image1.hide()
label1.hide()
while True:
  if (pir_0.state) == 1:
    rgb.setColorAll(0x000000)
    speaker.sing(659, 1/2)
    speaker.sing(330, 1/2)
    speaker.sing(659, 2)
    speaker.sing(523, 1/2)
    speaker.sing(659, 1/2)
    speaker.sing(784, 2)
    speaker.sing(392, 2)
    greeting1.show()
    greeting2.show()
    greeting1.hide()
    greeting1.hide()
    greeting1.hide()
    Price.hide()
    Shelf.hide()
    wait(1)
    greeting1.hide()
    greeting2.hide()
    wait(2)
    greeting1.hide()
    greeting1.hide()
    label0.hide()
    label2.hide()
    label3.hide()
    showetemlist()
    Itemselection()
  else:
    rgb.setColorAll(0xff0000)
  wait_ms(2)

Stock Checker Code (M5Stack2)

MicroPython
Requires RGB and ToF Unit
from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x222222)
tof_0 = unit.get(unit.TOF, unit.PORTA)
rgb_0 = unit.get(unit.RGB, unit.PORTB)






label0 = M5TextBox(19, 12, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label1 = M5TextBox(288, 10, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(19, 198, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(283, 212, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
C = M5TextBox(33, 74, "Chinese TYS O level", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label5 = M5TextBox(33, 126, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)

# Describe this function...
def TOF_function():
  label0.hide()
  label1.hide()
  label2.hide()
  label3.hide()
  label0.setText(str(tof_0.distance))
  while True:
    C.hide()
    if (tof_0.distance) <= 70:
      rgb.setColorAll(0x33cc00)
      rgb.setBrightness(100)
      rgb_0.setColorAll(0x33cc00)
      rgb_0.setBrightness(100)
      label5.setText('Stock: HIGH')
    if (tof_0.distance) > 70 and (tof_0.distance) <= 120:
      rgb.setColorAll(0xffcc00)
      rgb.setBrightness(100)
      rgb_0.setColorAll(0xffcc00)
      rgb_0.setBrightness(100)
      label5.setText('Stock: MEDIUM')
    if (tof_0.distance) > 120 and (tof_0.distance) < 160:
      rgb.setColorAll(0xff0000)
      rgb.setBrightness(100)
      rgb_0.setColorAll(0xff0000)
      rgb_0.setBrightness(100)
      label5.setText('Stock: LOW')
    if (tof_0.distance) >= 160:
      rgb.setColorAll(0xff0000)
      rgb.setBrightness(100)
      label5.setText('Unavailable.')
      wait_ms(500)
      rgb.setColorAll(0xff0000)
      rgb.setBrightness(0)
      wait_ms(500)
      rgb_0.setColorAll(0xff0000)
      rgb_0.setBrightness(100)
      wait_ms(500)
      rgb_0.setColorAll(0xff0000)
      rgb_0.setBrightness(0)
      wait_ms(500)
    wait_ms(2)



while True:
  TOF_function()
  wait_ms(2)

Credits

Matthew Yong
1 project • 0 followers
i unno
Zoolier YT
1 project • 0 followers
Radenoch Rioveros
1 project • 0 followers
School
hat _
1 project • 0 followers
kkekekekeh

Comments