🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5Paper V1.1 - Simple loop stops counting

    Scheduled Pinned Locked Moved UIFlow
    4 Posts 3 Posters 951 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RIDDSprojectsR Offline
      RIDDSprojects
      last edited by

      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

      uiflow_block_1768590699927.png

      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()
      

      ATOM LITE | ATOM MATRIX | CORE | CORE2 | STAMP-PICO | CORE.INK | PAPER V1.1
      RESEARCH | INNOVATION | DEVELOPMENT | DESIGN | SUSTAINABILITY
      and electronics

      Nederland

      V robskiR 2 Replies Last reply Reply Quote 0
      • V Offline
        veryalien @RIDDSprojects
        last edited by

        @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.

        1 Reply Last reply Reply Quote 1
        • robskiR Offline
          robski @RIDDSprojects
          last edited by

          @RIDDSprojects your Ynext end2 (805) must be diff to Ynext end (805) ... add 24?

          M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ, M5Tab, M5CardputerAdv, M5StackChan

          V 1 Reply Last reply Reply Quote 0
          • V Offline
            veryalien @robski
            last edited by

            @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.

            1 Reply Last reply Reply Quote 1

            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
            • First post
              Last post