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

    UIFlow
    3
    4
    6.0k
    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
      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
        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
          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
            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
            • First post
              Last post