View previous topic :: View next topic |
Author |
Message |
morebudwiser
Joined: 17 Oct 2005 Posts: 26
|
reading keypad input |
Posted: Fri Jan 20, 2006 2:15 pm |
|
|
hi i am using the ccs keypad driver to scan a 4x4 keypad. what i want to be able to do is store the values entered on the keypad to a variable for example if key 1 ,2 , 3 is pressed each value is read in and then stored to a variable with the value of one hundred and twenty three. can anyone please advise me on the best way to do this. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Jan 20, 2006 3:29 pm |
|
|
store the key scans in a array. put a \0 on the end to turn the array into a string. then run atoi atol.
look at help file. atoi and atol has "your" example exactly. |
|
|
JohnLeung
Joined: 18 May 2004 Posts: 15
|
Store keys |
Posted: Fri Jan 20, 2006 9:12 pm |
|
|
May try the followings:
char FreeHandNum[3]={0x20,0x20,0x20}; //initialize to empty space
..
..
main (){
char kchar
...
kchar=kbd_getc( );
//remember to adjust the debounce factor well for a 30-50ms debounce time
if (kchar!=0){
switch(kchar){
case function key:
....//do setup etc
break;
case numeric key: FreeHandNum[0]=FreeHandNum[1]; FreeHandNum[1]=FreeHandNum[2]; FreeHandNum[2]=kchar;
break;
}
}
...
} |
|
|
KamPutty Guest
|
|
Posted: Fri Jan 20, 2006 11:25 pm |
|
|
(Hi all)
You could also use a simple counter
EXAMPLE:
.
.
.
int counter=0;
.
.
n=number entered // 0, 1, 2 etc
.
counter=counter*10; //shift left one
counter=counter+n
.
. continue loop
For "1", "2", "3" we get
#1. Counter=0 (init)
#2. User entered "1" (I'm assuming numeric 1 and not character "1", else we simple do digitValue=characterValue-'0')
#3. Counter=Counter*10= 0 + 1
#4. Counter=1
#5. "2" Entered
#6. Counter=Counter*10=10+2
#7. Counter=12
#8. "3"
#9. Counter=Counter*10=120+3
#10. Counter=123
or just convert the string as mentioned above. many ways to do it!
~Kam (^8*
~Kam (^8* |
|
|
|