Hardware components | ||||||
| × | 1 |
M5Stack Faces kits are now programmable in Uiflow. Let's see how to program a basic Simon memory game. Check out the following video for a step by step instruction of how to create this project.
from m5stack import *
from m5ui import *
from uiflow import *
from emoji import Emoji
import face
setScreenColor(0x222222)
emoji0 = Emoji(7, 7, 15, 9)
faces_joystick = face.get(face.JOYSTICK)
label1 = M5TextBox(85, 104, "Text", lcd.FONT_DejaVu24,0xFFFFFF, rotate=0)
title1 = M5Title(title="Title", x=3 , fgcolor=0xFFFFFF, bgcolor=0x0000FF)
import random
directions = None
playing = None
sequence = None
input2 = None
i = None
directions = ['left', 'up', 'down', 'right']
playing = False
sequence = []
input2 = []
while True:
emoji0.show_normal(3)
title1.show()
while playing == False:
title1.setTitle('Get Ready')
wait(1)
sequence.append(directions[int(random.randint(0, 3) - 1)])
wait_ms(100)
for i in sequence:
if i == 'left':
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,1,0,0,0,0],[0,1,0,0,0,0,0],[1,1,1,1,1,1,1],[0,1,0,0,0,0,0],[0,0,1,0,0,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
elif i == 'up':
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,1,1,1,0,0],[0,1,0,1,0,1,0],[1,0,0,1,0,0,1],[0,0,0,1,0,0,0],[0,0,0,1,0,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
elif i == 'down':
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,0,1,0,0,0],[0,0,0,1,0,0,0],[1,0,0,1,0,0,1],[0,1,0,1,0,1,0],[0,0,1,1,1,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
else:
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,0,0,1,0,0],[0,0,0,0,0,1,0],[1,1,1,1,1,1,1],[0,0,0,0,0,1,0],[0,0,0,0,1,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
wait_ms(500)
emoji0.show_map([[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]], 0xFF0000)
wait_ms(100)
playing = True
while playing == True:
if (faces_joystick.X) < 300:
wait_ms(200)
input2.append('left')
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,1,0,0,0,0],[0,1,0,0,0,0,0],[1,1,1,1,1,1,1],[0,1,0,0,0,0,0],[0,0,1,0,0,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
elif (faces_joystick.X) > 750:
wait_ms(200)
input2.append('right')
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,0,0,1,0,0],[0,0,0,0,0,1,0],[1,1,1,1,1,1,1],[0,0,0,0,0,1,0],[0,0,0,0,1,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
elif (faces_joystick.Y) > 670:
wait_ms(200)
input2.append('up')
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,1,1,1,0,0],[0,1,0,1,0,1,0],[1,0,0,1,0,0,1],[0,0,0,1,0,0,0],[0,0,0,1,0,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
elif (faces_joystick.Y) < 370:
wait_ms(200)
input2.append('down')
emoji0.show_map([[0,0,0,1,0,0,0],[0,0,0,1,0,0,0],[0,0,0,1,0,0,0],[1,0,0,1,0,0,1],[0,1,0,1,0,1,0],[0,0,1,1,1,0,0],[0,0,0,1,0,0,0]], 0xFF0000)
elif input2 == sequence:
speaker.sing(523, 1)
title1.setTitle('You Win')
wait_ms(500)
input2 = []
playing = False
elif input2 != sequence and len(input2) >= len(sequence):
lcd.clear()
speaker.sing(220, 1)
label1.setText('Game Over')
wait(1)
input2 = []
sequence = []
playing = False
wait_ms(2)
lukasmaximus89
38 projects • 34 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