crystel hoecelesteYu QiWing Hong
Published

Engineering Exploration

M5Stack Project School

BeginnerFull instructions provided14
Engineering Exploration

Things used in this project

Story

Read more

Schematics

Block Diagram

Code

PIR +RGB Code Python

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

setScreenColor(0x222222)
pir_0 = unit.get(unit.PIR, unit.PORTB)
rgb_0 = unit.get(unit.RGB, unit.PORTB)


motion = None



label0 = M5TextBox(95, 82, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)




while True:
  label0.setText(str(pir_0.state))
  if (pir_0.state) == 1:
    rgb_0.setColorAll(0xffffcc)
    rgb_0.setBrightness(200)
  else:
    rgb_0.setBrightness(20)
    rgb_0.setColor(1, 0x000000)
    rgb_0.setColor(2, 0x000000)
    rgb_0.setColor(3, 0x000000)
  wait_ms(2)

TOF+ ENV Python Code

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

setScreenColor(0x222222)
env2_0 = unit.get(unit.ENV2, unit.PAHUB0)
tof_0 = unit.get(unit.TOF, unit.PAHUB5)
pahub_0 = unit.get(unit.PAHUB, unit.PORTA)


current = None
genre2 = None
genre1 = None



labelTemperature = M5TextBox(58, 157, "Temperature:", lcd.FONT_Default, 0x638dd9, rotate=0)
temperatureValue = M5TextBox(163, 157, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
tempOutput = M5TextBox(80, 193, "text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
image0 = M5Img(90, 35, "res/coolTemp.png", True)
genreone = M5TextBox(10, 203, "0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
genretwo = M5TextBox(44, 204, "0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
output1 = M5TextBox(44, 109, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
output2 = M5TextBox(189, 114, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0)
outputText = M5TextBox(44, 23, "text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0)
tof = M5TextBox(212, 42, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)

from numbers import Number



def buttonC_wasPressed():
  global current, genre2, genre1
  current = False
  pass
btnC.wasPressed(buttonC_wasPressed)

def buttonB_wasPressed():
  global current, genre2, genre1
  genre2 = (genre2 if isinstance(genre2, Number) else 0) + 1
  genretwo.setText(str(genre2))
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonA_wasPressed():
  global current, genre2, genre1
  genre1 = (genre1 if isinstance(genre1, Number) else 0) + 1
  genreone.setText(str(genre1))
  pass
btnA.wasPressed(buttonA_wasPressed)


genre1 = 0
genre2 = 0
output1.hide()
output2.hide()
outputText.hide()
tof.hide()
current = True
while True:
  if (tof_0.distance) > 200:
    tof.show()
    tof.setText('Understocked')
  else:
    tof.hide()
  if current == True:
    labelTemperature.show()
    temperatureValue.show()
    tempOutput.show()
    genreone.show()
    genretwo.show()
    if (env2_0.temperature) < 25:
      image0.show()
      temperatureValue.setText(str(env2_0.temperature))
      tempOutput.setText('Increase the temperature ')
      speaker.tone(1800, 50)
      rgb.setColorAll(0x000066)
      wait(0.5)
      rgb.setColorAll(0x000000)
      wait(0.5)
    else:
      image0.hide()
      temperatureValue.setText(str(env2_0.temperature))
      tempOutput.setText('Temperature is normal')
  else:
    tof.hide()
    labelTemperature.hide()
    temperatureValue.hide()
    tempOutput.hide()
    genreone.hide()
    genretwo.hide()
    output1.setText(str(genre1))
    output2.setText(str(genre2))
    if genre1 > genre2:
      outputText.setText('genre 2 should be cleared')
    else:
      outputText.setText('genre 1 should be cleared')
    output1.show()
    output2.show()
    outputText.show()
    wait(8)
    output1.hide()
    output2.hide()
    outputText.hide()
    current = True
  wait_ms(2)

Credits

crystel hoe

crystel hoe

1 project • 0 followers
celeste

celeste

1 project • 0 followers
Yu Qi

Yu Qi

0 projects • 0 followers
Wing Hong

Wing Hong

0 projects • 0 followers

Comments