M5Paper V1.1 - Simple loop stops counting
-
I created a simple loop to draw several squares (touch buttons) with text. However, the last square (the second loop) isn't filled with text, and the loop only loops 5 times.
What am I missing?Note:
UIFlow 1.0
I am using the screen horizontally.
960 pixels total (Y)
6 buttons, 125 pixels
30 pixels spacing
from m5stack import * from m5ui import * from uiflow import * setScreenColor(15) Ynext = None Counter = None from numbers import Number def upRange(start, stop, step): while start <= stop: yield start start += abs(step) def downRange(start, stop, step): while start >= stop: yield start start -= abs(step) Ynext = 0 Counter = 0 Ynext_end = float(960 - (125 + 30)) Ynext_inc = float(125 + 30) for Ynext in (30 <= Ynext_end) and upRange(30, Ynext_end, Ynext_inc) or downRange(30, Ynext_end, Ynext_inc): lcd.rect(380, int(Ynext), 125, 125, color=0) Ynext_end2 = float(960 - (125 + 30)) Ynext_inc2 = float(125 + 30) for Ynext in (54 <= Ynext_end2) and upRange(54, Ynext_end2, Ynext_inc2) or downRange(54, Ynext_end2, Ynext_inc2): Counter = (Counter if isinstance(Counter, Number) else 0) + 1 lcd.font(lcd.FONT_DejaVu40) lcd.print(((str('AC') + str(Counter))), 470, int(Ynext), 0, rotate=90) lcd.show() -
@RIDDSprojects I think you need to change your second loop to loop to a value of 960 - (125 + 54)) not 30. I think, without trying it myself, the second loop ends too soon because you are starting at offset 54, not at 30.
-
@RIDDSprojects your Ynext end2 (805) must be diff to Ynext end (805) ... add 24?
-
@robski Adding 24 is exactly the same as my solution, 30+24=54 and changing the "to" in the loop block will change the python end2 value. It should then work as expected.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login