Simple game sample, frustrating results - M5Flow
-
Hi
I'm sure many have been through this.
M5Flow blocks used for programming graphics and commands: testing if the interpreter is enough to assemble mid-fast interfaces.
Example attached:
Q any way to pass priority to the buttons' trigger and improve response?Kind regards
https://github.com/ipodjupiter/M5Stack.git
from m5stack import *
from m5ui import *
from uiflow import *setScreenColor(0x222222)
circle0 = M5Circle(92, 65, 15, 0xe21414, 0xFFFFFF)
rectangle1 = M5Rect(0, 220, 30, 15, 0xFFFFFF, 0x22f470)
label0 = M5TextBox(30, 113, "Text1", lcd.FONT_Default,0xFFFFFF, rotate=0)
label1 = M5TextBox(29, 145, "Text2", lcd.FONT_Default,0xFFFFFF, rotate=0)
label2 = M5TextBox(187, 117, "Text3", lcd.FONT_Default,0xFFFFFF, rotate=0)
label3 = M5TextBox(182, 155, "Text4", lcd.FONT_Default,0xFFFFFF, rotate=0)from numbers import Number
import random
import mathpos = None
circY = None
circX = None
destCircY = None
destCircX = Nonedef buttonA_wasPressed():
global pos, circY, circX, destCircY, destCircX
pos = (pos if isinstance(pos, Number) else 0) + -5
if pos < 0:
pos = 0
else:
pos = pos
pass
btnA.wasPressed(buttonA_wasPressed)def buttonC_wasPressed():
global pos, circY, circX, destCircY, destCircX
pos = (pos if isinstance(pos, Number) else 0) + 5
if pos >= 320:
pos = 320
else:
pos = pos
pass
btnC.wasPressed(buttonC_wasPressed)rectangle1.setPosition(150, 220)
pos = 150
circY = 0
circX = 0
circle0.setPosition(30, 30)
while True:
rectangle1.setPosition(x=pos)
destCircY = random.randint(0, 200)
destCircX = random.randint(0, 320)
while math.fabs(circX - destCircX) > 10 or math.fabs(circY - destCircY) > 10:
if destCircX - circX > 0:
circX = circX + 5
else:
circX = circX - 5
if destCircY - circY > 0:
circY = circY + 5
else:
circY = circY - 5
circle0.setPosition(circX, circY)
wait_ms(5)
wait_ms(2) -
@ipodlux Found it!
in order to compensate the slow reading of the interrupt I moved the reading in the loop. It less less classy that the external function but now it reacts as it should.