Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
tan jiayi
Published

Lyfe Watch

Introducing Lyfe Watch, designed to keep you active and help adapt a healthy lifestyle. Motivates you to stay fit with personalised workouts

BeginnerFull instructions provided-300 minutes75
Lyfe Watch

Things used in this project

Story

Read more

Schematics

Main Block Diagram

Main Flow Chart

ENVII and Earth Block Blocky Code (1)

ENVII and Earth Block Blocky Code (2)

ENVII and Earth Block Blocky Code (3)

ENVII and Earth Block Blocky Code (4)

ENVII and Earth Block Blocky Code (5)

TOF Blocky Code

RFID Blocky Code

Code

ENVII And Earth Code

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

setScreenColor(0x222222)
env2_1 = unit.get(unit.ENV2, unit.PAHUB1)
earth_1 = unit.get(unit.EARTH, unit.PORTB)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA)


mins = None
secs = None
hours = None



label0 = M5TextBox(118, 133, "Temp", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
label8 = M5TextBox(10, 141, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image3 = M5Img(0, 13, "res/default.jpg", True)
image4 = M5Img(110, 15, "res/default.jpg", True)
image5 = M5Img(220, 13, "res/default.jpg", True)
label1 = M5TextBox(10, 170, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label2 = M5TextBox(132, 170, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(234, 170, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(139, 200, "00", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(66, 200, "00", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(207, 200, "00", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label7 = M5TextBox(207, 139, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image1 = M5Img(110, 13, "res/default.jpg", True)
image2 = M5Img(220, 13, "res/default.jpg", True)
label9 = M5TextBox(95, 170, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image0 = M5Img(0, 13, "res/default.jpg", True)

from numbers import Number



def buttonA_wasDoublePress():
  global mins, secs, hours
  mins = (mins if isinstance(mins, Number) else 0) + 39
  pass
btnA.wasDoublePress(buttonA_wasDoublePress)

def buttonB_wasDoublePress():
  global mins, secs, hours
  secs = (secs if isinstance(secs, Number) else 0) + 5
  pass
btnB.wasDoublePress(buttonB_wasDoublePress)


image0.changeImg("res/default.jpg")
image1.changeImg("res/default.jpg")
image2.changeImg("res/default.jpg")
image3.changeImg("res/default.jpg")
image4.changeImg("res/default.jpg")
image5.changeImg("res/default.jpg")
secs = 0
mins = 0
hours = 0
label4.hide()
label5.hide()
label6.hide()
while True:
  if (env2_1.temperature) >= 28:
    rgb.setColorAll(0xff0000)
    label0.setText(str((str('Temp:') + str((env2_1.temperature)))))
    label1.setText('Swimming')
    label2.setText('Basketball')
    label3.setText('Cycling')
    label8.setText('Goal: 40 mins')
    label7.hide()
    label8.hide()
    label9.hide()
    image0.show()
    image1.show()
    image2.show()
    image3.hide()
    image4.hide()
    image5.hide()
    if btnA.wasPressed():
      label0.hide()
      label1.show()
      label2.hide()
      label3.hide()
      label4.show()
      label5.show()
      label6.show()
      label7.show()
      label9.show()
      while True:
        label7.setText(str(earth_1.analogValue))
        label9.setText(str((str('Temp:') + str((env2_1.temperature)))))
        label7.show()
        label8.show()
        image0.show()
        image1.hide()
        image2.hide()
        if (earth_1.analogValue) > 0:
          if secs >= 59:
            mins = (mins if isinstance(mins, Number) else 0) + 1
            secs = 0
            if mins >= 59:
              hours = (hours if isinstance(hours, Number) else 0) + 1
              mins = 0
              if hours >= 24:
                secs = 0
                mins = 0
                hours = 0
            if mins >= 40:
              rgb.setColorAll(0x33ff33)
          wait(1)
          secs = (secs if isinstance(secs, Number) else 0) + 1
          label6.setText(str(secs))
          label5.setText(str(mins))
          label4.setText(str(hours))
        wait_ms(2)
    elif btnB.wasPressed():
      while True:
        label1.hide()
        label2.show()
        label3.hide()
        label7.hide()
        label8.show()
        image0.hide()
        image2.hide()
        image1.show()
        wait_ms(2)
    elif btnC.wasPressed():
      label8.setText('Goal: 60 mins')
      while True:
        label1.hide()
        label2.hide()
        label3.show()
        label7.hide()
        label8.show()
        image0.hide()
        image1.hide()
        image2.show()
        wait_ms(2)
else:
    rgb.setColorAll(0x3366ff)
    label0.setText(str((str('Temp:') + str((env2_1.temperature)))))
    label1.setText('Indoor running')
    label2.setText('Dance')
    label3.setText('Yoga')
    label0.show()
    label1.show()
    label2.show()
    label3.show()
    label4.hide()
    label5.hide()
    label6.hide()
    label7.hide()
    label8.hide()
    label9.hide()
    image0.hide()
    image1.hide()
    image2.hide()
    image3.show()
    image4.show()
    image5.show()
    if btnA.wasPressed():
      label8.setText('Goal: 40 mins')
      while True:
        label0.show()
        label1.show()
        label2.hide()
        label3.hide()
        label8.show()
        image3.show()
        image4.hide()
        image5.hide()
        wait_ms(2)
    elif btnB.wasPressed():
      label8.setText('Goal: 45 mins')
      while True:
        label1.hide()
        label2.show()
        label3.hide()
        label8.show()
        image4.show()
        image3.hide()
        image5.hide()
        wait_ms(2)
    elif btnC.wasPressed():
      label8.setText('Goal: 60 mins')
      while True:
        label1.hide()
        label2.hide()
        label3.show()
        label8.show()
        image5.show()
        image4.hide()
        image3.hide()
        wait_ms(2)
  wait_ms(2)

TOF Code

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

setScreenColor(0x222222)
tof_1 = unit.get(unit.TOF, unit.PAHUB0)
pahub_1 = unit.get(unit.PAHUB, unit.PORTA)


exercise_count = None



label0 = M5TextBox(41, 116, "0", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label1 = M5TextBox(34, 73, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label2 = M5TextBox(34, 29, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label3 = M5TextBox(28, 160, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)

from numbers import Number




exercise_count = 0
while True:
  label2.setText('Exercise tracker')
  label1.setText(str((str('TOF distance:') + str((tof_1.distance)))))
  label3.setText('Go nearer to the TOF sensor')
  label3.hide()
  if (tof_1.distance) <= 110:
    exercise_count = (exercise_count if isinstance(exercise_count, Number) else 0) + 1
    label0.setText(str(exercise_count))
    speaker.tone(1800, 200)
    wait(3)
  else:
    if (tof_1.distance) > 111:
      label3.show()
      wait(1)
  wait_ms(2)

RFID Code

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

setScreenColor(0x222222)
rfid_0 = unit.get(unit.RFID, unit.PAHUB2)
pahub_2 = unit.get(unit.PAHUB, unit.PORTA)


step_count = None



label0 = M5TextBox(187, 107, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label1 = M5TextBox(37, 107, "Distance:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label2 = M5TextBox(37, 36, "Goal:", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
label3 = M5TextBox(132, 36, "Achieve 8KM", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)

from numbers import Number




step_count = 0
label2.setText('Goal:')
label3.setText('Achieve 8 KM')
label0.hide()
while True:
  if rfid_0.isCardOn():
    step_count = (step_count if isinstance(step_count, Number) else 0) + 1
    speaker.tone(1800, 200)
    label0.setText(str((str(step_count) + str('KM'))))
    wait(1)
  wait_ms(2)

Credits

tan jiayi
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.