lukasmaximus89
Published © GPL3+

M5Stack Faces Encoder Etch A Sketch

An M5Stack version of the classic Etch A Sketch.

BeginnerWork in progress1 hour1,789
M5Stack Faces Encoder Etch A Sketch

Things used in this project

Story

Read more

Code

etchasketch.py

MicroPython
Etch a sketch code
from m5stack import *
from m5ui import *
from uiflow import *
import face

setScreenColor(0x222222)

faces_encode = face.get(face.ENCODE)
label1 = M5TextBox(28, 213, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
label2 = M5TextBox(112, 210, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
label3 = M5TextBox(196, 210, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)

xpos = None
ypos = None

xpos = 160
ypos = 120
faces_encode.clearValue()
while True:
  label1.setText(str(faces_encode.getValue()))
  label2.setText(str(faces_encode.getDir()))
  if (btnA.isPressed()) and (faces_encode.getDir()) == 0:
    xpos = (xpos if isinstance(xpos, int) else 0) + 1
  elif (btnA.isPressed()) and (faces_encode.getDir()) == 1:
    xpos = (xpos if isinstance(xpos, int) else 0) + -1
  elif (btnB.isPressed()) and (faces_encode.getDir()) == 0:
    ypos = (ypos if isinstance(ypos, int) else 0) + 1
  elif (btnB.isPressed()) and (faces_encode.getDir()) == 1:
    ypos = (ypos if isinstance(ypos, int) else 0) + -1
  elif xpos >= 320:
    xpos = 320
  elif xpos <= 0:
    xpos = 0
  elif ypos <= 0:
    ypos = 0
  elif ypos >= 240:
    ypos = 240
  lcd.pixel(xpos, ypos, 0xffffff)
  wait_ms(2)

Credits

lukasmaximus89

lukasmaximus89

38 projects • 33 followers
I'm Luke from Manchester, UK. I've been living in shenzhen for 6 years. I do 3D design, Basic Electronics, Casting and other cool stuff.

Comments