Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : uMite strangeness
Author | Message | ||||
viscomjim Guru Joined: 08/01/2014 Location: United StatesPosts: 925 |
I cannont for the life of me figure this one out... Have a 4x4 keyboard on 44 pin uMite and here is code... Option autorun on KeyPad keycode, kp_int, 21, 22, 23, 24, 25, 26, 27, 32 do keycode = 99 print "first = " keycode do:loop until keycode <> 99 print "second = " keycode loop kp_int: IReturn when run this is what happens... first = 99 second = -1 over and over. the second do loop falls through even as keycode prints that its 99, without any keys being pressed and somehow makes keycode = -1. I tested the keypad using this program and every key works just fine... Option autorun on KeyPad keycode, kp_int, 21, 22, 23, 24, 25, 26, 27, 32 do:loop kp_int: print "keycode = " keycode IReturn Please show me the errors of my ways. I am loosing what little hair I have left. Thanks!!!! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
The use of keycode may clear the value in it. Try assigning the value of keycode to a variable and test the variable. The "cleared" value in keycode may be -1. That is no key pressed then keycode=-1. We corrected Geoff a couple of days back. The word is "losing" your hair not "loosing" and I don't have much left either. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6102 |
Bob is close. The value of the variable 'keycode' cannot be trusted to remain at the last entered key code. Not mentioned in the manual, but it looks like -1 is used to indicate 'no key pressed' The following gets around that problem: I have used pins suitable for the 28 pin mucroMite. KeyPad keycode, kp_int, 2, 3, 4, 5, 6, 7, 9, 10
do mykeycode = 99 print "first = " mykeycode do:loop until mykeycode <> 99 print "second = " mykeycode loop kp_int: mykeycode = keycode IReturn I stopped having to worry about losing any more hair a long time ago... Jim VK7JH MMedit MMBasic Help |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3196 |
This is my fault, for some reason I used the variable to record if no key press was detected, hence the -1 value. My only excuse is that I must have had a "bad hair day" (I still have a little left). Jim's suggestion is an excellent solution. Because it is a minor bug with a good workaround I will leave the fix for the next release. Geoff Geoff Graham - http://geoffg.net |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2350 |
an argument could be put that if this behaviour was documented, then it would not be a bug at all. certainly, it is a perfectly acceptable way for the keypad functionality to work - my suggestion is to simply add this behaviour to the specification in the manual. rob :-) |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
I agree with rob! I would call it a feature!! Just needsto be documented. You could then use it similarly to the inkey$. Very useful for hold and repeat operations. Microblocks. Build with logic. |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Viscomjim might also have been mis-directed by a couple of posts in this thread Umite keypad and interrupts posted 18th March 10:12 & 10:59pm. |
||||
Print this page |