cardkb GetKey comparison
-
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?
-
Use change not set.
-
@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.
-
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. -
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. -
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.
-
@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...
-
@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?
-
@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.