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

    cardkb GetKey comparison

    UIFlow
    3
    9
    9.2k
    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.
    • X
      xkcd
      last edited by xkcd

      Hello
      I'm trying to read the cardkb buttons to do something (see screenshot). On the display of the m5stack I can see the values when I release the buttons on the cardkb, however, the values for my red, green, blue variables always stay zero. Any insights on what I'm doing wrong?
      0_1594028703632_5babf40d-7090-4413-8da9-edf118d937b4-grafik.png

      1 Reply Last reply Reply Quote 0
      • ajb2k3A
        ajb2k3
        last edited by

        Use change not set.

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        X 1 Reply Last reply Reply Quote 0
        • X
          xkcd @ajb2k3
          last edited by

          @ajb2k3 I'd like to know the reasoning behind this. Can't imagine I can't just set a value. I tried to debug a little more:
          The rectangle changes color (and the values change as well) when i press one of the 3 buttons on the m5stack, but not if I press the keys on the card.
          What is the return type of the get Key function? As it says ASCII value I assume it's an integer, but it's not triggering anything.
          0_1594136547556_02e2bd28-5066-41b6-8589-f25782ac1c82-grafik.png

          1 Reply Last reply Reply Quote 0
          • ajb2k3A
            ajb2k3
            last edited by

            My understanding from the way it goes wrong on my projects.
            Set is used to set the initial state.
            to alter the value of the initial state, you need to change.

            UIFlow, so easy an adult can learn it!
            If I don't know it, be patient!
            I've ether not learned it or am too drunk to remember it!
            Author of the WIP UIFlow Handbook!
            M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

            1 Reply Last reply Reply Quote 0
            • X
              xkcd
              last edited by

              I just tried to use change and put different values, but the outcome is the same - none of the "do" parts get executed through the "get Key" condition.
              They do get executed when through the A B C Buttons though.

              1 Reply Last reply Reply Quote 0
              • world101W
                world101
                last edited by world101

                getKey seems to return a hex value not decimal. So your if condition = 180, 181, 182, 183 is not being satisfied and the do is never executed. Try converting hex to decimal first, before your if statements. Or you can try comparing on the string values B4, B5, B6, B7 or 0xB4, 0xB5, 0xB6, 0xB7. I don’t have a CardKB to test with, so it might take some trial and error.

                X 1 Reply Last reply Reply Quote 1
                • X
                  xkcd @world101
                  last edited by xkcd

                  @world101 said in cardkb GetKey comparison:

                  getKey seems to return a hex value not decimal. So your if condition = 180, 181, 182, 183 is not being satisfied and the do is never executed. Try converting hex to decimal first, before your if statements. Or you can try comparing on the string values B4, B5, B6, B7 or 0xB4, 0xB5, 0xB6, 0xB7. I don’t have a CardKB to test with, so it might take some trial and error.

                  I suspected this at the very beginning. I can't put B4 in the numerical field (obviously), but I can input 0xB4 - which immediately gets converted to 180.
                  When I press the '1' Button on the cardKB, GetKey returns 49 - which equals 0x31, the ASCII Code for '1'.
                  It feels like the condition isn't true for long enough...

                  Edit: It seems I just figured it out. I have to set a variable with the getKey function, if I then check the value of the variable, it works...

                  ajb2k3A 1 Reply Last reply Reply Quote 1
                  • ajb2k3A
                    ajb2k3 @xkcd
                    last edited by

                    @xkcd said in cardkb GetKey comparison:

                    @world101 said in cardkb GetKey comparison:

                    getKey seems to return a hex value not decimal. So your if condition = 180, 181, 182, 183 is not being satisfied and the do is never executed. Try converting hex to decimal first, before your if statements. Or you can try comparing on the string values B4, B5, B6, B7 or 0xB4, 0xB5, 0xB6, 0xB7. I don’t have a CardKB to test with, so it might take some trial and error.

                    I suspected this at the very beginning. I can't put B4 in the numerical field (obviously), but I can input 0xB4 - which immediately gets converted to 180.
                    When I press the '1' Button on the cardKB, GetKey returns 49 - which equals 0x31, the ASCII Code for '1'.
                    It feels like the condition isn't true for long enough...

                    Edit: It seems I just figured it out. I have to set a variable with the getKey function, if I then check the value of the variable, it works...

                    Can you share the working code as I'm yet to start work on both of the keyboards?

                    UIFlow, so easy an adult can learn it!
                    If I don't know it, be patient!
                    I've ether not learned it or am too drunk to remember it!
                    Author of the WIP UIFlow Handbook!
                    M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                    X 1 Reply Last reply Reply Quote 0
                    • X
                      xkcd @ajb2k3
                      last edited by

                      @ajb2k3
                      sure, here you go:
                      It didn't seem to matter where I put key = getKey, also it's really messy, but it's working for now.
                      0_1594456304041_cardKB1.png

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post