Soon You KernAng wei junErnst Lee
Published

Healthy Eating Machine with M5Stack

We aim to design a sustainable technology solution to make healthier diet options convenient for youths and adults with busy schedules.

BeginnerShowcase (no instructions)13 hours361
Healthy Eating Machine with M5Stack

Things used in this project

Hardware components

M5Stack FIRE IoT Development Kit (PSRAM 2.0)
M5Stack FIRE IoT Development Kit (PSRAM 2.0)
×2
Mini Angle Unit Potentiometer Inside
M5Stack Mini Angle Unit Potentiometer Inside
×1
Mini RFID Unit RC522 Module Sensor
M5Stack Mini RFID Unit RC522 Module Sensor
×1
Time-of-Flight (ToF) VL53L0X Laser Ranging Unit (MCP4725/)
M5Stack Time-of-Flight (ToF) VL53L0X Laser Ranging Unit (MCP4725/)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Scissor, Electrician
Scissor, Electrician
Tape, Scotch
Tape, Scotch
Tape, Masking
Tape, Masking

Story

Read more

Schematics

Front View (3D Prototype)

This is the front view of our project.

Right View (3D Prototype)

Left View (3D Prototype)

Back View (3D Prototype)

The components and wiring of our project.

m5stack_project_M34WhUn700.zip

jo

HEM model on Tinkercad

This is the barebone structure of where the M5stack, sensors and servo are placed on the HEM model. (Click on the README.md file to open the Tinkercad file)

Code

M5Stack A code

Python
from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import time
import unit

setScreenColor(0x1b1818)
angle_0 = unit.get(unit.ANGLE, unit.PORTB)
tof_0 = unit.get(unit.TOF, unit.PORTA)


mac = None
Data_send = None
InputC = None
Display = None
maxchoice = None
BMR = None
choice = None
gender = None
Calorie = None
BMRtoCAL = None
age = None
my_2_2Choice = None
height = None
Activeness = None
weight = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()

label0 = M5TextBox(3, 9, "Height:", lcd.FONT_Default, 0xefe8e8, rotate=0)
heigh = M5TextBox(58, 9, "Text", lcd.FONT_Default, 0xf7f2f2, rotate=0)
GenText = M5TextBox(3, 30, "Gender:", lcd.FONT_Default, 0xeee7e7, rotate=0)
Gender = M5TextBox(58, 31, "Text", lcd.FONT_Default, 0xf2eded, rotate=0)
Agetext = M5TextBox(3, 53, "Age:", lcd.FONT_Default, 0xf4ecec, rotate=0)
ag = M5TextBox(38, 53, "Age", lcd.FONT_Default, 0xf0e7e7, rotate=0)
label1 = M5TextBox(3, 74, "Weight:", lcd.FONT_Default, 0xf1eaea, rotate=0)
Weight = M5TextBox(58, 74, "Text", lcd.FONT_Default, 0xf5ebeb, rotate=0)
Activenestext = M5TextBox(3, 95, "Activeness:", lcd.FONT_Default, 0xf2efef, rotate=0)
ActivenessReal = M5TextBox(88, 95, "Text", lcd.FONT_Default, 0xf4eded, rotate=0)
BMRTEXT = M5TextBox(13, 126, "BMR:", lcd.FONT_Default, 0xf9f5f5, rotate=0)
BM = M5TextBox(52, 126, "Text", lcd.FONT_Default, 0xf9f4f4, rotate=0)
CalText1 = M5TextBox(13, 156, "Recommended", lcd.FONT_Default, 0xf8f0f0, rotate=0)
caltext2 = M5TextBox(13, 173, "Daily Calorie Intake:", lcd.FONT_Default, 0xefebeb, rotate=0)
cal = M5TextBox(170, 173, "Text", lcd.FONT_Default, 0xf9eeee, rotate=0)
rectangleYes = M5Rect(31, 202, 100, 30, 0x0f0e0e, 0xFFFFFF)
rectangleNo = M5Rect(172, 202, 100, 30, 0x020101, 0xFFFFFF)
labelYes = M5TextBox(68, 209, "Yes", lcd.FONT_Default, 0xFFFFFF, rotate=0)
labelNo = M5TextBox(212, 209, "No", lcd.FONT_Default, 0xFFFFFF, rotate=0)
GainWeight = M5TextBox(40, 209, "Gain weight", lcd.FONT_Default, 0xffffff, rotate=0)
Loseweight = M5TextBox(179, 209, "Lose Weight", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Displa = M5TextBox(222, 9, "Display", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(106, 9, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
rectangle0 = M5Rect(220, 38, 100, 30, 0x111010, 0xffffff)
rectangle1 = M5Rect(220, 95, 100, 30, 0x000000, 0xffffff)
BMRChoice = M5TextBox(253, 45, "BMR", lcd.FONT_Default, 0xFFFFFF, rotate=0)
RecipeChoice = M5TextBox(242, 102, "Recipes", lcd.FONT_Default, 0xFFFFFF, rotate=0)
rectangle2 = M5Rect(220, 156, 100, 30, 0x000000, 0xFFFFFF)
BuyChoice = M5TextBox(242, 163, "Buy food", lcd.FONT_Default, 0xFFFFFF, rotate=0)
BuyingShow = M5TextBox(106, 102, "Buying.", lcd.FONT_Default, 0xffffff, rotate=0)
BuyInstruct2 = M5TextBox(38, 141, "Please head to the other display ", lcd.FONT_Default, 0xFFFFFF, rotate=0)
BuyInstruct = M5TextBox(38, 156, "for purchases", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Layer1 = M5Rect(0, 0, 300, 300, 0xFFFFFF, 0xFFFFFF)

from numbers import Number


# Describe this function...
def LoseGain():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  Display = 'LoseGain'
  Displa.setText(str(Display))
  GainLoseChoiceShow()
  Selected()
  HideChoice()

# Describe this function...
def showMainChoice():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  BuyChoice.show()
  BMRChoice.show()
  RecipeChoice.show()

# Describe this function...
def YesNoChoiceShow2():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  UNHighlightchoice2()
  HighlightMainchoice()
  labelYes.show()
  labelNo.show()

# Describe this function...
def HideBMR():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  label0.hide()
  cal.hide()
  caltext2.hide()
  CalText1.hide()
  BM.hide()
  BMRTEXT.hide()
  ActivenessReal.hide()
  Activenestext.hide()
  Weight.hide()
  label1.hide()
  ag.hide()
  Agetext.hide()
  Gender.hide()
  GenText.hide()
  label2.hide()
  heigh.hide()

# Describe this function...
def ShowBMR():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  label0.show()
  cal.show()
  caltext2.show()
  CalText1.show()
  BM.show()
  BMRTEXT.show()
  ActivenessReal.show()
  Activenestext.show()
  Weight.show()
  label1.show()
  ag.show()
  Agetext.show()
  Gender.show()
  GenText.show()
  heigh.show()

# Describe this function...
def GainLoseChoiceShow():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  UNHighlightchoice2()
  HighlightMainchoice()
  GainWeight.show()
  Loseweight.show()

# Describe this function...
def HighlightMainchoice():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  if Display == 'Main':
    if choice == 1:
      rectangle0.show()
    elif choice == 2:
      rectangle1.show()
    elif choice == 3:
      rectangle2.show()
  elif Display == 'LoseGain':
    if choice == 1:
      rectangleYes.show()
    else:
      rectangleNo.show()
  elif Display == 'YesNo':
    if choice == 1:
      rectangleYes.show()
    else:
      rectangleNo.show()

# Describe this function...
def UNHighlightchoice2():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  if Display == 'Main':
    if choice != 1:
      rectangle0.hide()
    if choice != 2:
      rectangle1.hide()
    if choice != 3:
      rectangle2.hide()
  elif Display == 'LoseGain':
    if choice != 1:
      rectangleYes.hide()
    if choice != 2:
      rectangleNo.hide()
  elif Display == 'YesNo':
    if choice != 1:
      rectangleYes.hide()
    if choice != 2:
      rectangleNo.hide()

# Describe this function...
def MaxchoiceOnDisplay():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  if Display == 'Main':
    maxchoice = 3
  elif Display == 'YesNo':
    maxchoice = 2
  elif Display == 'LoseGain':
    maxchoice = 2

# Describe this function...
def Selected():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  while Display == 'Main':
    if InputC == 1:
      if choice == 1:
        Display = 'BMR'
      elif choice == 2:
        Display = 'Recipes'
      elif choice == 3:
        Display = 'Buy'
    wait_ms(100)
  while Display == 'YesNo' or Display == 'LoseGain':
    if InputC == 1:
      if choice == 1:
        my_2_2Choice = 1
      elif choice == 2:
        my_2_2Choice = 2
      Display = 'Main'
    wait_ms(100)

# Describe this function...
def AskValue():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  Displa.setText(str(Display))
  if Display == 'Main':
    Display = 'Gender'
  elif Display == 'Gender':
    GenText.show()
    while Display == 'Gender':
      gender = int(((angle_0.read()) * (2 / 1024) - 0))
      wait_ms(100)
      if gender == 1:
        Gender.setText('F')
      else:
        Gender.setText('M')
      if InputC == 1:
        Display = 'Height'
  elif Display == 'Height':
    label0.show()
    label2.show()
    while Display == 'Height':
      height = 2 - (tof_0.distance) / 1000
      heigh.setText(str(height * 10))
      label2.setText(str(height))
      wait_ms(100)
      if InputC == 1:
        Display = 'Age'
  elif Display == 'Age':
    Agetext.show()
    while Display == 'Age':
      age = int(((angle_0.read()) * (60 / 1024) + 10))
      ag.setText(str(age))
      if InputC == 1:
        Display = 'weight'
  elif Display == 'weight':
    label1.show()
    while Display == 'weight':
      wait_ms(100)
      weight = int((30 + (angle_0.read()) * (120 / 1024)))
      Weight.setText(str(weight))
      if InputC == 1:
        Display = 'Activeness'
  elif Display == 'Activeness':
    Activenestext.show()
    while Display == 'Activeness':
      wait_ms(100)
      Activeness = int((1 + (angle_0.read()) * (4 / 1024)))
      ActivenessReal.setText(str(Activeness))
      if InputC == 1:
        Display = 'Main'
  InputC = 0

# Describe this function...
def HideChoice():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  RecipeChoice.hide()
  BMRChoice.hide()
  BuyChoice.hide()
  rectangle2.hide()
  rectangle1.hide()
  rectangle0.hide()
  labelYes.hide()
  Loseweight.hide()
  GainWeight.hide()
  labelNo.hide()
  rectangleNo.hide()
  rectangleYes.hide()

# Describe this function...
def Main():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  MaxchoiceOnDisplay()
  InputC = 0
  Displa.setText(str(Display))
  HideChoice()
  if Display == 'BMR':
    BMR2()
  elif Display == 'Recipes':
    HideBMR()
    espnow.send(id=1, data=str('1'))
    while not Data_send == '1':
      BuyingShow.setText('On recipes')
      BuyInstruct.setText('for recipes')
      BuyInstruct.show()
      BuyInstruct2.show()
      BuyingShow.show()
    BuyInstruct.setText('for purchase')
    BuyingShow.setText('Buying.')
    Data_send = 0
    BuyingShow.hide()
    BuyInstruct.hide()
    BuyInstruct2.hide()
  elif Display == 'Buy':
    espnow.send(id=1, data=str(2))
    HideBMR()
    while not Data_send == '1':
      BuyInstruct.show()
      BuyInstruct2.show()
      BuyingShow.show()
      BuyingShow.setText('Buying..')
      wait_ms(800)
      BuyingShow.setText('Buying...')
      wait_ms(600)
      BuyingShow.setText('Buying.')
      wait_ms(600)
    BuyInstruct.hide()
    BuyingShow.hide()
    BuyInstruct2.hide()
    Data_send = 0
  Display = 'Main'
  InputC = 0
  Displa.setText(str(Display))

# Describe this function...
def BMR2():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  Display = 'Gender'
  while Display != 'Main':
    AskValue()
    InputC = 0
  Displa.setText(str(Display))
  CalcBMR()
  ShowBMR()
  LoseGain()
  if my_2_2Choice == 1:
    Calorie = Calorie + 300
  else:
    Calorie = Calorie - 300
  cal.setText(str(Calorie))

# Describe this function...
def CalcBMR():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  if gender == 0:
    BMR = 625 * height + (weight * 10 + (5 - age * 5))
  else:
    BMR = 625 * height + (weight * 10 - (5 + age * 5))
  BM.setText(str(BMR))
  if Activeness == 1:
    BMRtoCAL = 1.2
  elif Activeness == 2:
    BMRtoCAL = 1.375
  elif Activeness == 3:
    BMRtoCAL = 1.55
  elif Activeness == 4:
    BMRtoCAL = 1.725
  else:
    BMRtoCAL = 1.9
  Calorie = BMR * BMRtoCAL
  cal.setText(str(Calorie))



def recv_cb(_):
  global mac,Data_send,InputC,Display,maxchoice,BMR,choice,gender,Calorie,BMRtoCAL,my_2_2Choice,age,height,Activeness,weight
  mac, _, Data_send = espnow.recv_data(encoder='str')
  speaker.tone(1800, 200)

  pass
espnow.recv_cb(recv_cb)


def buttonB_wasPressed():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  MaxchoiceOnDisplay()
  if choice != 1:
    choice = (choice if isinstance(choice, Number) else 0) + -1
  if Display == 'Main':
    UNHighlightchoice2()
    HighlightMainchoice()
    showMainChoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow2()
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonC_wasPressed():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  InputC = 1
  Displa.setText(str(Display))
  pass
btnC.wasPressed(buttonC_wasPressed)

def buttonB_wasPressed():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  MaxchoiceOnDisplay()
  if choice != 1:
    choice = (choice if isinstance(choice, Number) else 0) + -1
  if Display == 'Main':
    UNHighlightchoice2()
    HighlightMainchoice()
    showMainChoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow2()
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonA_wasPressed():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  MaxchoiceOnDisplay()
  if maxchoice > choice:
    choice = (choice if isinstance(choice, Number) else 0) + 1
  if Display == 'Main':
    UNHighlightchoice2()
    HighlightMainchoice()
    showMainChoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow2()
  pass
btnA.wasPressed(buttonA_wasPressed)


espnow.add_peer('78:21:84:93:ac:09', id=1)
Layer1.hide()
HideBMR()
Calorie = 'Null'
while True:
  HideChoice()
  Data_send = 0
  BuyingShow.hide()
  Display = 'Main'
  choice = 1
  InputC = 0
  my_2_2Choice = 1
  MaxchoiceOnDisplay()
  Displa.setText(str(Display))
  InputC = 0
  if Display == 'Main':
    UNHighlightchoice2()
    HighlightMainchoice()
    showMainChoice()
  Selected()
  choice = 1
  HideChoice()
  Main()
  wait_ms(2)

def buttonA_wasPressed():
  global mac, Data_send, InputC, Display, maxchoice, BMR, choice, gender, Calorie, BMRtoCAL, my_2_2Choice, age, height, Activeness, weight
  MaxchoiceOnDisplay()
  if maxchoice > choice:
    choice = (choice if isinstance(choice, Number) else 0) + 1
  if Display == 'Main':
    UNHighlightchoice2()
    HighlightMainchoice()
    showMainChoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow2()
  pass
btnA.wasPressed(buttonA_wasPressed)

M5stackB code

Python
from m5stack import *
from m5ui import *
from uiflow import *
import espnow
import wifiCfg
import time
import unit

setScreenColor(0x1b1818)
rfid_1 = unit.get(unit.RFID, unit.PORTA)
servo_0 = unit.get(unit.SERVO, unit.PORTB)


mac = None
Data_send = None
InputC = None
Display = None
choice = None
maxchoice = None
out = None
Product = None
my_2_2Choice = None

wifiCfg.wlan_ap.active(True)
wifiCfg.wlan_sta.active(True)
espnow.init()

item2Re = M5Rect(110, 10, 100, 30, 0x000000, 0xFFFFFF)
Item3rectangle = M5Rect(210, 10, 100, 30, 0x000000, 0xFFFFFF)
IngredientsText = M5TextBox(42, 209, "Ingredients", lcd.FONT_Default, 0xFFFFFF, rotate=0)
stepsText = M5TextBox(218, 209, "Steps", lcd.FONT_Default, 0xFFFFFF, rotate=0)
rectangleYes = M5Rect(30, 202, 100, 30, 0x0f0e0e, 0xFFFFFF)
rectangleNo = M5Rect(188, 202, 100, 30, 0x020101, 0xFFFFFF)
labelYes = M5TextBox(67, 209, "Yes", lcd.FONT_Default, 0xFFFFFF, rotate=0)
labelNo = M5TextBox(229, 209, "No", lcd.FONT_Default, 0xFFFFFF, rotate=0)
GainWeight = M5TextBox(39, 209, "Gain weight", lcd.FONT_Default, 0xffffff, rotate=0)
Loseweight = M5TextBox(195, 209, "Lose Weight", lcd.FONT_Default, 0xFFFFFF, rotate=0)
BackRectangle = M5Rect(125, 162, 70, 30, 0x000000, 0xFFFFFF)
BackText = M5TextBox(143, 170, "Back", lcd.FONT_Default, 0xFFFFFF, rotate=0)
BuydiplayRect = M5Rect(10, 10, 300, 150, 0x1b1818, 0xFFFFFF)
SaleItemName = M5TextBox(19, 47, "text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
step2 = M5TextBox(18, 79, "Text", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=0)
step3 = M5TextBox(18, 91, "Text", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=0)
SaleCalText = M5TextBox(197, 129, "Cal:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Step4 = M5TextBox(18, 102, "Text", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=0)
SaleCalValue = M5TextBox(224, 129, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
step5 = M5TextBox(18, 114, "Text", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=0)
PriceText = M5TextBox(30, 112, "Price:", lcd.FONT_Default, 0xFFFFFF, rotate=0)
PriceValue = M5TextBox(75, 112, "$", lcd.FONT_Default, 0xFFFFFF, rotate=0)
PayInstruc = M5TextBox(30, 129, "Payment by card only", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Purchase = M5TextBox(123, 144, "Purchase?", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Item1Rect = M5Rect(10, 10, 100, 30, 0x000000, 0xFFFFFF)
item1Text = M5TextBox(19, 17, "LoseWeight", lcd.FONT_Default, 0xFFFFFF, rotate=0)
item2 = M5TextBox(131, 17, "Maintain", lcd.FONT_Default, 0xFFFFFF, rotate=0)
item3 = M5TextBox(220, 18, "GainWeight", lcd.FONT_Default, 0xFFFFFF, rotate=0)
ItemName = M5TextBox(19, 47, "Name: ", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Step1 = M5TextBox(18, 66, "Text", lcd.FONT_DefaultSmall, 0xFFFFFF, rotate=0)
label0 = M5TextBox(70, 85, "Please use the other display", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number


# Describe this function...
def linesShow():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  BuydiplayRect.show()
  Step1.show()
  step2.show()
  step3.show()
  Step4.show()
  step5.show()

# Describe this function...
def HighlightMainchoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  if Display == 'Main':
    if choice == 1:
      rectangleYes.show()
    elif choice == 2:
      rectangleYes.show()
    elif choice == 3:
      rectangleYes.show()
  elif Display == 'LoseGain':
    if choice == 1:
      rectangleYes.show()
    elif choice == 3:
      BackRectangle.show()
    else:
      rectangleNo.show()
  elif Display == 'YesNo':
    if choice == 1:
      rectangleYes.show()
    else:
      rectangleNo.show()
  elif Display == 'Recipes':
    if choice == 1:
      Item1Rect.show()
    elif choice == 2:
      item2Re.show()
    elif choice == 3:
      Item3rectangle.show()
    else:
      BackRectangle.show()
  elif Display == 'Stepinstruc':
    if choice == 1:
      rectangleYes.show()
    elif choice == 3:
      BackRectangle.show()
    else:
      rectangleNo.show()

# Describe this function...
def ShowLoseChoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  BuydiplayRect.show()
  SaleCalText.show()
  SaleCalValue.show()
  PriceText.show()
  PriceValue.show()
  PayInstruc.show()
  Purchase.show()
  ItemName.setText('Peanut Butter-Banana Cinnamon Toast')
  SaleCalValue.setText('260')
  PriceValue.setText('$2.00')

# Describe this function...
def GainChoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  Display = 'GainBuy'
  ShowGainChoice()
  YesNo()

# Describe this function...
def Selected():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  choice = 1
  InputC = 0
  while Display == 'YesNo' or Display == 'LoseGain':
    if InputC == 1:
      if choice == 1:
        my_2_2Choice = 1
      elif choice == 2:
        my_2_2Choice = 2
      elif choice == 3:
        my_2_2Choice = 3
      Display = 'Buy'
    wait_ms(100)
  while Display == 'Recipes':
    if InputC == 1:
      if choice == 1:
        my_2_2Choice = 1
      elif choice == 2:
        my_2_2Choice = 2
      elif choice == 3:
        my_2_2Choice = 3
      elif choice == 4:
        my_2_2Choice = 4
      Display = 'Buy'
    wait_ms(100)
  while Display == 'Stepinstruc':
    if InputC == 1:
      if choice == 3:
        out = 1
        Display = 'Recipes'
      InputC = 0
    wait_ms(100)
  while Display == 'paying':
    if rfid_1.isCardOn():
      my_2_2Choice = 3
      Display = 'serve'
    elif InputC == 1:
      Display = 'buy'
    wait_ms(100)
  choice = 1
  InputC = 0

# Describe this function...
def ShowRecipesChoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  UNHighlightchoice2()
  BuydiplayRect.show()
  HighlightMainchoice()
  ItemName.show()
  item1Text.show()
  item2.show()
  item3.show()
  BackText.show()

# Describe this function...
def LoseChoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  Display = 'LoseBuy'
  choice = 1
  ShowLoseChoice()
  YesNo()

# Describe this function...
def MotorReset():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  servo_0.write_angle(60)

# Describe this function...
def YesNo():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  Display = 'YesNo'
  YesNoChoiceShow()
  choice = 1
  Selected()
  HideAll()

# Describe this function...
def stepIngredShow():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  wait_ms(50)
  UNHighlightchoice2()
  HighlightMainchoice()
  if my_2_2Choice == 1:
    if choice == 1:
      Step1.setText('1 slice whole-wheat bread, toasted')
      step2.setText('1 tbsp of peanut butter')
      step3.setText('1 small banana, sliced')
      Step4.setText('Cinnamon (optional)')
      step5.setText('1 serving')
    else:
      Step1.setText('Spread toast with peanut butter')
      step2.setText('Top with banana slices')
      step3.setText('Sprinkle with cinnamon for flavour')
      Step4.setText(' ')
      step5.setText(' ')
  elif my_2_2Choice == 2:
    if choice == 1:
      Step1.setText('2 tbps cider vinegar, 1 tbsp canola oil')
      step2.setText('2 cups red cabbage, 1/4 cup cilantro')
      step3.setText('1/4 tsp salt, 1 carrot, 15oz rinsed white beans')
      Step4.setText('1/2 cup Cheddar cheese,  2 tbsp red onion')
      step5.setText('1 ripe avocado, 4 (8-10 in) whole-wheat wraps')
    else:
      Step1.setText('Whisk vinegar, oil, chipotle chile and salt. ')
      step2.setText('Add cabbage, carrot and cilantro. ')
      step3.setText('Mash beans and avocado, stir in cheese and onion.')
      Step4.setText('1/2 cup of the bean-avocado mixture per wrap')
      step5.setText('2/3 cup of the cabbage-carrot slaw per wrap. Roll')
  elif my_2_2Choice == 3:
    if choice == 1:
      Step1.setText('2 tsp avocado oil,1lb lean chicken thigh ')
      step2.setText('1 cup Sauteed Peppers & Onions')
      step3.setText('1 cup tomato sauce, 4 slices provolone cheese')
      Step4.setText('4 (6 inch) whole-wheat sub rolls')
      step5.setText('4 servings ')
    else:
      Step1.setText('Preheat the oven with a baking sheet with foil.')
      step2.setText('Heat oil in a skillet over medium-high heat ')
      step3.setText('Add chicken, oregano, salt (cook 4-6min)')
      Step4.setText('Add the pepper and onions. Put Rolls in oven')
      step5.setText('Top buns with cooked ingredients. Add cheese ')
  linesShow()
  ItemName.show()
  stepsText.show()
  IngredientsText.show()
  BackText.show()

# Describe this function...
def GainLoseChoiceShow():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  UNHighlightchoice2()
  HighlightMainchoice()
  GainWeight.show()
  Loseweight.show()
  BackText.show()

# Describe this function...
def YesNoChoiceShow():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  UNHighlightchoice2()
  HighlightMainchoice()
  labelYes.show()
  labelNo.show()

# Describe this function...
def UNHighlightchoice2():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  if Display == 'Main':
    if choice != 1:
      rectangleYes.hide()
    if choice != 2:
      rectangleYes.hide()
    if choice != 3:
      rectangleYes.hide()
  elif Display == 'LoseGain':
    if choice != 1:
      rectangleYes.hide()
    if choice != 3:
      BackRectangle.hide()
    if choice != 2:
      rectangleNo.hide()
  elif Display == 'YesNo':
    if choice != 1:
      rectangleYes.hide()
    if choice != 2:
      rectangleNo.hide()
  elif Display == 'Recipes':
    if choice != 1:
      Item1Rect.hide()
    if choice != 2:
      item2Re.hide()
    if choice != 3:
      Item3rectangle.hide()
    if choice != 4:
      BackRectangle.hide()
  elif Display == 'Stepinstruc':
    if choice != 1:
      rectangleYes.hide()
    if choice != 2:
      rectangleNo.hide()
    if choice != 3:
      BackRectangle.hide()

# Describe this function...
def MotorServe():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  if Product == 1:
    servo_0.write_angle(0)
  elif Product == 2:
    servo_0.write_angle(120)

# Describe this function...
def ShowGainChoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  BuydiplayRect.show()
  SaleCalText.show()
  SaleCalValue.show()
  PriceText.show()
  PriceValue.show()
  PayInstruc.show()
  Purchase.show()
  ItemName.setText('Chicken&Provolone Sandwich')
  SaleCalValue.setText('480')
  PriceValue.setText('$5.00')

# Describe this function...
def MaxchoiceOnDisplay():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  if Display == 'LoseGain':
    maxchoice = 3
  elif Display == 'YesNo':
    maxchoice = 2
  elif Display == 'GainBuy':
    maxchoice = 1
  elif Display == 'LoseBuy':
    maxchoice = 1
  elif Display == 'Recipes':
    maxchoice = 4
  elif Display == 'Stepinstruc':
    maxchoice = 3

# Describe this function...
def Paying():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  Display = 'paying'
  BackRectangle.show()
  BackText.show()
  Purchase.show()
  InputC = 0
  Selected()

# Describe this function...
def ShowStepsIngreChoice():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  IngredientsText.show()
  stepsText.show()
  ItemName.show()
  item1Text.show()
  item2.show()
  item3.show()
  BackText.show()

# Describe this function...
def HideAll():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  labelYes.hide()
  labelNo.hide()
  GainWeight.hide()
  Loseweight.hide()
  rectangleYes.hide()
  rectangleNo.hide()
  BackRectangle.hide()
  BuydiplayRect.hide()
  Item1Rect.hide()
  item2Re.hide()
  Item3rectangle.hide()
  SaleItemName.hide()
  SaleCalText.hide()
  SaleCalValue.hide()
  PriceText.hide()
  PriceValue.hide()
  PayInstruc.hide()
  Purchase.hide()
  Step1.hide()
  step2.hide()
  step3.hide()
  Step4.hide()
  step5.hide()
  item2.hide()
  item3.hide()
  item1Text.hide()
  BackText.hide()
  IngredientsText.hide()
  stepsText.hide()
  label0.hide()

# Describe this function...
def Recipes():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  while not my_2_2Choice == 4:
    out = 0
    UNHighlightchoice2()
    HighlightMainchoice()
    choice = 1
    InputC = 0
    Display = 'Recipes'
    ShowRecipesChoice()
    ItemName.setText('Name: Peanut Butter-Banana Toast ')
    wait_ms(100)
    Selected()
    if my_2_2Choice != 4:
      while not out == 1:
        ItemName.show()
        UNHighlightchoice2()
        HighlightMainchoice()
        Display = 'Stepinstruc'
        stepIngredShow()
        Selected()
      out = 0
      linesHide()

# Describe this function...
def LoseGain():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  Display = 'LoseGain'
  choice = 1
  HighlightMainchoice()
  GainLoseChoiceShow()
  Selected()
  HideAll()

# Describe this function...
def Buy():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  while not (my_2_2Choice == 3 and Display == 'Buy'):
    Display = 'Buy'
    choice = 1
    Product = 0
    my_2_2Choice = 0
    LoseGain()
    Display = 'Buy'
    if my_2_2Choice == 1:
      my_2_2Choice = 0
      Product = 1
      GainChoice()
    elif my_2_2Choice == 2:
      my_2_2Choice = 0
      Product = 2
      LoseChoice()
    wait_ms(100)
    InputC = 0
    if my_2_2Choice == 1:
      Paying()
    if Display == 'serve':
      MotorServe()
      wait(5)
      my_2_2Choice = 3
      MotorReset()
    Display = 'Buy'
    HideAll()

# Describe this function...
def linesHide():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  Step1.hide()
  step2.hide()
  step3.hide()
  Step4.hide()
  step5.hide()



def recv_cb(_):
  global mac,Data_send,InputC,Display,choice,maxchoice,out,Product,my_2_2Choice
  mac, _, Data_send = espnow.recv_data(encoder='str')
  rgb.setColorAll(0x000000)

  pass
espnow.recv_cb(recv_cb)


def buttonA_wasPressed():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  MaxchoiceOnDisplay()
  if maxchoice > choice:
    choice = (choice if isinstance(choice, Number) else 0) + 1
  UNHighlightchoice2()
  HighlightMainchoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow()
  elif Display == 'LoseBuy':
    ShowLoseChoice()
  elif Display == 'GainBuy':
    ShowGainChoice()
  elif Display == 'Recipes':
    ShowRecipesChoice()
    if choice == 1:
      ItemName.setText('Name: Peanut Butter-Banana Toast ')
      ItemName.show()
    elif choice == 2:
      ItemName.setText('Name: Advovado&Beans Wrap')
      ItemName.show()
    elif choice == 3:
      ItemName.setText('Name: Chicken&Provolone Sandwich')
      ItemName.show()
  elif Display == 'Stepinstruc':
    stepIngredShow()
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonC_wasPressed():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  InputC = 1
  pass
btnC.wasPressed(buttonC_wasPressed)

def buttonB_wasPressed():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  MaxchoiceOnDisplay()
  if choice != 1:
    choice = (choice if isinstance(choice, Number) else 0) + -1
  UNHighlightchoice2()
  HighlightMainchoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow()
  elif Display == 'LoseBuy':
    ShowLoseChoice()
  elif Display == 'Recipes':
    ShowRecipesChoice()
    if choice == 1:
      ItemName.setText('Name: Peanut Butter-Banana Toast ')
      ItemName.show()
    elif choice == 2:
      ItemName.setText('Name: Advovado&Beans Wrap')
      ItemName.show()
    elif choice == 3:
      ItemName.setText('Name: Chicken&Provolone Sandwich')
      ItemName.show()
  elif Display == 'GainBuy':
    ShowGainChoice()
  elif Display == 'Stepinstruc':
    stepIngredShow()
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonB_wasPressed():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  MaxchoiceOnDisplay()
  if choice != 1:
    choice = (choice if isinstance(choice, Number) else 0) + -1
  UNHighlightchoice2()
  HighlightMainchoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow()
  elif Display == 'LoseBuy':
    ShowLoseChoice()
  elif Display == 'Recipes':
    ShowRecipesChoice()
    if choice == 1:
      ItemName.setText('Name: Peanut Butter-Banana Toast ')
      ItemName.show()
    elif choice == 2:
      ItemName.setText('Name: Advovado&Beans Wrap')
      ItemName.show()
    elif choice == 3:
      ItemName.setText('Name: Chicken&Provolone Sandwich')
      ItemName.show()
  elif Display == 'GainBuy':
    ShowGainChoice()
  elif Display == 'Stepinstruc':
    stepIngredShow()
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonC_wasPressed():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  InputC = 1
  pass
btnC.wasPressed(buttonC_wasPressed)


espnow.add_peer('78:21:84:93:b9:f9', id=1)
BuydiplayRect.hide()
HideAll()
Data_send = '0'
InputC = 0
my_2_2Choice = 0
rgb.setColorAll(0xffffff)
MotorReset()
while True:
  if Data_send == '1' or Data_send == '2':
    HideAll()
    my_2_2Choice = 0
    if Data_send == '1':
      Display = 'Recipes'
      Recipes()
    else:
      Display = 'Buy'
      Buy()
    HideAll()
    espnow.send(id=1, data=str('1'))
    MotorReset()
    rgb.setColorAll(0xffffff)
    Data_send = 0
  HideAll()
  wait_ms(2)

def buttonA_wasPressed():
  global mac, Data_send, InputC, Display, choice, maxchoice, out, Product, my_2_2Choice
  MaxchoiceOnDisplay()
  if maxchoice > choice:
    choice = (choice if isinstance(choice, Number) else 0) + 1
  UNHighlightchoice2()
  HighlightMainchoice()
  if Display == 'LoseGain':
    GainLoseChoiceShow()
  if Display == 'YesNo':
    YesNoChoiceShow()
  elif Display == 'LoseBuy':
    ShowLoseChoice()
  elif Display == 'GainBuy':
    ShowGainChoice()
  elif Display == 'Recipes':
    ShowRecipesChoice()
    if choice == 1:
      ItemName.setText('Name: Peanut Butter-Banana Toast ')
      ItemName.show()
    elif choice == 2:
      ItemName.setText('Name: Advovado&Beans Wrap')
      ItemName.show()
    elif choice == 3:
      ItemName.setText('Name: Chicken&Provolone Sandwich')
      ItemName.show()
  elif Display == 'Stepinstruc':
    stepIngredShow()
  pass
btnA.wasPressed(buttonA_wasPressed)

Credits

Soon You Kern
1 project • 1 follower
Ang wei jun
0 projects • 1 follower
Ernst Lee
0 projects • 2 followers

Comments