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

    How to set data type and intial values.

    Scheduled Pinned Locked Moved UIFlow
    4 Posts 3 Posters 7.5k Views 2 Watching
    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.
    • B Offline
      birdsong
      last edited by birdsong

      How can a make blockly keep a data type? this Function doesnt work, because 0.1 rounds down to 0 every time the code is executed. It is for an hour meter, I want to add 0.1 every 6mins.
      This is what blockly automaticaly generates;

      if bTm6min and bRunFan:
          fPvHrs = (fPvHrs if isinstance(fPvHrs, Number) else 0) + 0.1
      

      0_1592806677383_e35ec1e8-1252-4746-a254-da89f9c85bbc-image.png
      When i manually change the code the problem goes away until blockly reverts back to the old code again.

      fPvHrs = fPvHrs + 0.1
      1 Reply Last reply Reply Quote 0
      • m5stackM Online
        m5stack
        last edited by

        the bug seem like from micropython. so , maybe you could use other way to change variable.
        eg:

        替代文字

        1 Reply Last reply Reply Quote 0
        • R Offline
          robalstona
          last edited by

          Ewentually add 1 instead 0.1 and the end of your calculations divide a value by 10.

          1 Reply Last reply Reply Quote 0
          • B Offline
            birdsong
            last edited by

            0_1592860978166_40e7c48f-ca80-431d-82c3-efcb57ba89cd-image.png
            Converts to;

              if bRunFan and bRunFan != bRunFanOld:
                fPvHrs = 0.01
              if bTm6min and bRunFan:
                fPvHrs = fPvHrs + 0.01
              bRunFanOld = bRunFan
            

            Thanks M5stack, this worked.
            I didn't want to divide by 10 because I would have to do that everywhere, slow the execution speed, its a slippery slope. The esp32 has very long divide instruction time compared to addition and multiplication.

            1 Reply Last reply Reply Quote 0

            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