Introduction: 1, 2 ,3, Run to the Wall, Freeze
Lately, I've been playing with the 5MstickC, and ESP32 based controller already packed with a screen, WiFi, Bluetooth, Gyro, Accelerometer, IR blaster...
It is very easy to program using the block programming UI Flow software, but you also have the ability to program it with either microPython or Arduino IDE...
Anyway, in this example I have made the 123, run to the wall, freeze game adding a PIR sensor and a Piezo buzzer.
Supplies
5MStickC
PIR Sensor
Piezo Buzzer
PCB
Step 1: Making the PCB
The PCB is only so i could connect the buzzer and the PIR sensor easily.
The Speaker is connected to Pin 26,
The PIR sensor is connected to Pin 36, 5v and GND
Step 2: UI Flow Programming
This is how it looks in the UI Flow programming.
Step 3: Same But in MicroPython
from m5stack import *
from m5ui import * from uiflow import * from easyIO import * import time import hat import hat
setScreenColor(0x111111)
hat_pir0 = hat.get(hat.PIR)
Gotya = M5Img(0, 0, "res/bucket.jpg", True) img_frz = M5Img(0, 0, "res/frz.jpg", True) label0 = M5TextBox(17, 40, "FREEZE", lcd.FONT_DejaVu24,0x000000, rotate=50) Count = M5TextBox(20, 49, "1", lcd.FONT_DejaVu72,0xFFFFFF, rotate=0)
from numbers import Number
hlong = None sPass = None lPass = None roundTime = None found = None startTime = None
def my_123fish(): global hlong, sPass, lPass, roundTime, found, startTime Count.show() toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(lPass) Count.setText('1') toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(lPass) Count.setText('2') toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(sPass) toggleIO(26) wait_ms(lPass) Count.setText('3') toggleIO(26) wait_ms((lPass * 4)) toggleIO(26) Count.hide()
def Beep(hlong): global sPass, lPass, roundTime, found, startTime toggleIO(26) wait_ms(hlong) toggleIO(26)
def buttonA_wasDoublePress(): global hlong, sPass, lPass, roundTime, found, startTime axp.powerOff() pass btnA.wasDoublePress(buttonA_wasDoublePress)
M5Led.off() Count.hide() label0.hide() img_frz.hide() Gotya.hide() digitalWrite(26, False) lPass = 200 sPass = 100 roundTime = 15 found = False while True: my_123fish() startTime = rtc.now()[5] if startTime + roundTime >= 59: startTime = (startTime if isinstance(startTime, Number) else 0) + (0 - (59 - startTime)) img_frz.show() label0.show() while not (hat_pir0.state): if (rtc.now()[5]) >= startTime + roundTime: break label0.hide() img_frz.hide() found = (found if isinstance(found, Number) else 0) + (hat_pir0.state) if found: setScreenColor(0xff0000) Gotya.show() M5Led.on() Beep(2000) wait(1) setScreenColor(0x000000) Gotya.hide() M5Led.off() found = False wait_ms(2)
Step 4: Got Ya
All Left is to upload the two images to the controller and also the sketch...
...and go play... Enjoy