View Full Version : Manipulating keypad presses
dbachman
- 3rd January 2011, 03:18
Hello:
I am scanning a keyad and am receiving and converting the rows and columns to numbers. I am wanting to display the numbers from 0 to 360 on an LCD. It is working as I am using a for next loop to put the key presses into an array. I then multiply the first one by a hundred and so on. But, if I only enter a 2 digit number I have to lead it with a zero, Is there and easier way?
Let me clarify this a little: I actually want to save say the number 320 in a variable after getting it from a keypad one press at a time and use it to control PWM cycles.
Thanks, Don
mister_e
- 3rd January 2011, 04:14
Not sure to follow you but let's see.
' Pseudo, for entertainement only or you'll be changed to a pumpkin at midnight
Number=0
Duty=0
DoIt:
LCDOUT $FE,1,"Number=",dec number
Call KeyPad Routine
IF KeyPad Scan routine Return a valid single decimal number entry Then
Number = (Number *10) + KeyPadValue
'
' Some test to make sure you're in the max duty range
'
GOTO DoIt
ENDIF
If Number !=Duty then
Duty=Number
HPWM 1,freq, Number
endif
GOTO DoIt
dbachman
- 3rd January 2011, 04:51
Mister_E
Actually I am using your keypad scan routine.
I am using a
for x = 1 to 3
gosub getkey
array[x] = keypress
next x
total = array[x]*100 + array[x]*10 + array[x]
But I have to make 3 entries in the array to satisfy the for next loop. So I have to use a leading zero if I enter anything less than 100. It works fine its just a pain.
mister_e
- 3rd January 2011, 04:58
No you don't need, read my example above again, there's this IF THEN line after the Keypad reading...
</pre>
dbachman
- 3rd January 2011, 05:09
Steve,
I guess I am still a little confused .
If I go get a keypress and I just pushed 3 for example. How is that moved three decimal places (multiplied by a 100) and then added to the next keypress which must be moved over 2 places?
I will study it some more but I am not "seeing" it yet.
Thanks for taking the time.
Don
mister_e
- 3rd January 2011, 05:19
How many key do you have on your Keypad? any left to be used as "enter" key?
dbachman
- 3rd January 2011, 05:22
I have 16 keys. I am using "E" or I think #14 as enter now for another routine.
mister_e
- 3rd January 2011, 05:37
A small hint
if keypress<=9 then
Number=(Number*10)+KeyPress
GOTO DoIt
Endif
dbachman
- 4th January 2011, 05:09
I finally got it........
Thanks Steve
mister_e
- 4th January 2011, 06:26
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3184&d=1234223382
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.