CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

reading keypad input

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
morebudwiser



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

reading keypad input
PostPosted: Fri Jan 20, 2006 2:15 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Jan 20, 2006 3:29 pm     Reply with quote

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

View user's profile Send private message

Store keys
PostPosted: Fri Jan 20, 2006 9:12 pm     Reply with quote

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







PostPosted: Fri Jan 20, 2006 11:25 pm     Reply with quote

(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*
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group