View previous topic :: View next topic |
Author |
Message |
springwheel
Joined: 12 Apr 2017 Posts: 3
|
3x4 Matrix mobile like keypad |
Posted: Wed Apr 12, 2017 4:28 pm |
|
|
Hi, I'm having some difficulties trying to develop a code to a mobile like keypad.
It should work like old mobile phones.
If you press the number 2 3x is should print the letter C.
I'm using the kbd_getc() function to get the inputs.
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Apr 12, 2017 6:53 pm |
|
|
Quick code...
Once you press a key, you start a short timer.. if you don't press that key again within the 'timeout' period, you'll get the 'first' press key code( A) in your example.
If you press that key within the time period, you get the '2nd' press key code(B), and restart the timer. When the timer expires, you exit the routine.
If you press that key again, you get the '3rd' press key code ( C) and exit the routine.
As for the timer delay, I suggest you start at 100ms. For the 'key press' codes, it could be a series of 'case' statements..easy to implement or a 'matrix' array that mimics the keypad layout.
I'd have to find a 30 year old QB45 program for real code.....
Jay |
|
|
springwheel
Joined: 12 Apr 2017 Posts: 3
|
|
Posted: Wed Apr 12, 2017 8:17 pm |
|
|
temtronic wrote: | Quick code...
Once you press a key, you start a short timer.. if you don't press that key again within the 'timeout' period, you'll get the 'first' press key code( A) in your example.
If you press that key within the time period, you get the '2nd' press key code(B), and restart the timer. When the timer expires, you exit the routine.
If you press that key again, you get the '3rd' press key code ( C) and exit the routine.
As for the timer delay, I suggest you start at 100ms. For the 'key press' codes, it could be a series of 'case' statements..easy to implement or a 'matrix' array that mimics the keypad layout.
I'd have to find a 30 year old QB45 program for real code.....
Jay |
Thanks for the heads up!
I was having some problems implementing it but I'm gonna try it again. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu Apr 13, 2017 1:52 am |
|
|
I'd just fractionally modify the flow.
Normally the time is perhaps 0.5 to 1 second, and no key gets accepted till this expires. So it goes A B C A B C, until you stop. Then accepts the key.
Problem is that if you press once too often, as posted it'd accept the 'C' and start on the next character. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Apr 13, 2017 6:10 am |
|
|
Ttelmah wrote: | I'd just fractionally modify the flow.
Normally the time is perhaps 0.5 to 1 second, and no key gets accepted till this expires. So it goes A B C A B C, until you stop. Then accepts the key.
Problem is that if you press once too often, as posted it'd accept the 'C' and start on the next character. |
If you want it to be like a mobile phone, I'd suggest the flow be:
2 A B C 2 A B C
3 D E F 3 D E F
etc. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu Apr 13, 2017 6:36 am |
|
|
Yes.
I was using a phone that has a separate numeric 'shift', but for the more common TV remote, or traditional phone, as Newguy says, it should include the numeric value as one step.... |
|
|
springwheel
Joined: 12 Apr 2017 Posts: 3
|
|
Posted: Thu Apr 13, 2017 3:25 pm |
|
|
I am having some hard time implementing the short timer.
How do I reset the timer ?
Could someone help me ?
I am trying to use a flag.
Code: | int8 i;
int1 flag;
#int_timer0
void timer0(){
set_timer0(131-get_timer0());
i++;
if(i==250){
disable_interrupts(GLOBAL | INT_TIMER0);
i=0;
flag=0;
}else{
flag=1;
}
}
void main(){
char c,aux;
int8 contador=1;
setup_counters(RTCC_INTERNAL, WDT_2304MS);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_32 );
set_timer0(131);
lcd_init();
kbd_init();
port_b_pullups(true);
lcd_putc("\f");
lcd_gotoxy(1,1);
while(1){
c = kbd_getc();
if(c != 0){
switch(c){
case '1':
if(!flag){
aux = c;
enable_interrupts(GLOBAL | INT_TIMER0);
}
if(flag){
aux = 'a';
}
break;
}
lcd_putc(aux);
}
}
} |
Sorry for the noob question, I am new to this. |
|
|
|