Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 02:29 20 May 2024 Privacy Policy
Jump to

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 States
Posts: 925
Posted: 01:14pm 28 Apr 2014
Copy link to clipboard 
Print this post

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: Australia
Posts: 935
Posted: 01:33pm 28 Apr 2014
Copy link to clipboard 
Print this post

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.
Edited by BobD 2014-04-29
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 03:50pm 28 Apr 2014
Copy link to clipboard 
Print this post

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: Australia
Posts: 3167
Posted: 07:00pm 28 Apr 2014
Copy link to clipboard 
Print this post

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 Zealand
Posts: 2294
Posted: 07:37pm 28 Apr 2014
Copy link to clipboard 
Print this post

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: Thailand
Posts: 2209
Posted: 08:59pm 28 Apr 2014
Copy link to clipboard 
Print this post

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: Australia
Posts: 1329
Posted: 09:53pm 28 Apr 2014
Copy link to clipboard 
Print this post

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.

  paceman said  
  robert.rozee said   ... and, of course, one can process a keystroke (in polled mode) then set KeyCode to an unused value (such as -1). you then just need to wait for KeyCode to change value again to indicate the next keypress - i've not tried this, but it looks fairly obvious that it should work ok.
rob :-)

It works fine that way Rob. I'm doing that on UV lamp exposure controller now I'm working on now - code below. I just set it to 99 and loop till "keypress" returns as other than 99. I also got it to assign the 99 to another variable and convert it to a string but that's unnecessary - I just haven't changed it from some playing I was doing.[/Quote]
I had previously tried Rob's "-1" suggestion but couldn't get it to work either so changed it to the "99" technique quoted above which did work. I wasn't at all sure my code was OK but guess if I'd mentioned it then the fix would already now be in the current MicroMite firmware. Guess I should have qualified my "It works fine that way Rob" statement but in the context of that thread, I meant the technique of polling the variable as Rob mentioned, not the "-1" being OK.

Anyway it's sorted now and I agree with Rob and TZ that a mod to the Manual is the way to go - maybe include TassyJim's example.

As an aside to this I'll start a new topic with the code I finalised a month or so ago which uses a very similar treatment for keypad input and LCD display, just to document it properly.

Greg
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024