Keypad problem revisited!
Hi Everyone,
This is my first shot at programming a stamp. I have connected to
pins 0-9 a very simple keypad which fires the appropriate pin for
numbers 0 - 9. This part seems to be working well enough.
I am building a 100 disc CD jukebox that needs to get a 4-digit input
from the keypad like 4502 (which would later extract 45 for the disc #
and 02 for the track #, then pulse the changer's disc-up and track-up
buttons thru an optoisolator).
The proper DEBUG result of this test program for an input of 4502
should be this:
KEY PRESSED = 4
DIGIT = 1
KEY PRESSED = 5
DIGIT = 2
KEY PRESSED = 0
DIGIT = 3
KEY PRESSED = 2
DIGIT = 4
RESULT = 4502
Right now it actually comes back with:
KEY PRESSED = 4
DIGIT = 1
KEY PRESSED = 5
DIGIT = 2
KEY PRESSED = 0
DIGIT = 3
KEY PRESSED = 5
DIGIT = 2
[noparse][[/noparse]NO RESULT DISPLAYED!]
Here is the code thus far:
'{$STAMP BS2}
'======DECLARE VARIABLES====
BT VAR BYTE(9)
KP VAR NIB(4)
DIGIT VAR NIB
SCAN VAR NIB
DIGIT = 1
LOOP: 'GRAB 4 KEY PRESSES FROM PINS 0 - 9
FOR SCAN = 0 TO 9
BUTTON SCAN,1,255,250,BT(SCAN),0,NOPRESS
KP(DIGIT)=SCAN
DEBUG "KEY PRESSED = "
DEBUG DEC KP(DIGIT),CR
DEBUG "DIGIT = "
DEBUG DEC DIGIT, CR, CR
DIGIT = DIGIT + 1
IF DIGIT > 4 THEN RESULT
GOTO LOOP
NOPRESS:
NEXT
GOTO LOOP
RESULT:
DEBUG "RESULT--> "
FOR SCAN = 1 TO 4
DEBUG DEC KP(SCAN)
NEXT
DEBUG CR,"
",CR
DIGIT = 1
GOTO LOOP
I know the keypad is connected properly because the "KEY PRESSED"
debug displays the proper key that I hit (usually). I have the keypad
connected properly per the "BUTTON" command.
HERE ARE SOME OTHER RESULTS FROM TESTS:
Entering 9876 returns result 0877
1234 returns 0235
6789 returns 157810!
2345 returns 0346
5555 returns 0556
Also 1111, 2222, 3333 or any keypad input combination of 1-2-3 never
shows a "RESULT" on the screen, as the DIGIT variable gets to 3 then
is re-set to 1 somehow.
I am sure I am doing something wrong with variables or arrays, but
have been at this for days now and am completely stuck! I hope
someone can look at my code, or even run it on their own stamp, and
shed some light on the problem(s) with my logic!
Thanks for the insight! Brian Dalziel - Milwaukee, WI USA
This is my first shot at programming a stamp. I have connected to
pins 0-9 a very simple keypad which fires the appropriate pin for
numbers 0 - 9. This part seems to be working well enough.
I am building a 100 disc CD jukebox that needs to get a 4-digit input
from the keypad like 4502 (which would later extract 45 for the disc #
and 02 for the track #, then pulse the changer's disc-up and track-up
buttons thru an optoisolator).
The proper DEBUG result of this test program for an input of 4502
should be this:
KEY PRESSED = 4
DIGIT = 1
KEY PRESSED = 5
DIGIT = 2
KEY PRESSED = 0
DIGIT = 3
KEY PRESSED = 2
DIGIT = 4
RESULT = 4502
Right now it actually comes back with:
KEY PRESSED = 4
DIGIT = 1
KEY PRESSED = 5
DIGIT = 2
KEY PRESSED = 0
DIGIT = 3
KEY PRESSED = 5
DIGIT = 2
[noparse][[/noparse]NO RESULT DISPLAYED!]
Here is the code thus far:
'{$STAMP BS2}
'======DECLARE VARIABLES====
BT VAR BYTE(9)
KP VAR NIB(4)
DIGIT VAR NIB
SCAN VAR NIB
DIGIT = 1
LOOP: 'GRAB 4 KEY PRESSES FROM PINS 0 - 9
FOR SCAN = 0 TO 9
BUTTON SCAN,1,255,250,BT(SCAN),0,NOPRESS
KP(DIGIT)=SCAN
DEBUG "KEY PRESSED = "
DEBUG DEC KP(DIGIT),CR
DEBUG "DIGIT = "
DEBUG DEC DIGIT, CR, CR
DIGIT = DIGIT + 1
IF DIGIT > 4 THEN RESULT
GOTO LOOP
NOPRESS:
NEXT
GOTO LOOP
RESULT:
DEBUG "RESULT--> "
FOR SCAN = 1 TO 4
DEBUG DEC KP(SCAN)
NEXT
DEBUG CR,"
",CR
DIGIT = 1
GOTO LOOP
I know the keypad is connected properly because the "KEY PRESSED"
debug displays the proper key that I hit (usually). I have the keypad
connected properly per the "BUTTON" command.
HERE ARE SOME OTHER RESULTS FROM TESTS:
Entering 9876 returns result 0877
1234 returns 0235
6789 returns 157810!
2345 returns 0346
5555 returns 0556
Also 1111, 2222, 3333 or any keypad input combination of 1-2-3 never
shows a "RESULT" on the screen, as the DIGIT variable gets to 3 then
is re-set to 1 somehow.
I am sure I am doing something wrong with variables or arrays, but
have been at this for days now and am completely stuck! I hope
someone can look at my code, or even run it on their own stamp, and
shed some light on the problem(s) with my logic!
Thanks for the insight! Brian Dalziel - Milwaukee, WI USA
Comments
> Hi Everyone,
>
> This is my first shot at programming a stamp. I have connected to
> pins 0-9 a very simple keypad which fires the appropriate pin for
> numbers 0 - 9. This part seems to be working well enough.
>
> I am building a 100 disc CD jukebox that needs to get a 4-digit
input
> from the keypad like 4502 (which would later extract 45 for the disc
#
> and 02 for the track #, then pulse the changer's disc-up and
track-up
> buttons thru an optoisolator).
>
> The proper DEBUG result of this test program for an input of 4502
> should be this:
>
> KEY PRESSED = 4
> DIGIT = 1
> KEY PRESSED = 5
> DIGIT = 2
> KEY PRESSED = 0
> DIGIT = 3
> KEY PRESSED = 2
> DIGIT = 4
>
> RESULT = 4502
>
> Right now it actually comes back with:
>
> KEY PRESSED = 4
> DIGIT = 1
> KEY PRESSED = 5
> DIGIT = 2
> KEY PRESSED = 0
> DIGIT = 3
> KEY PRESSED = 5
> DIGIT = 2
>
> [noparse][[/noparse]NO RESULT DISPLAYED!]
>
> Here is the code thus far:
> '{$STAMP BS2}
> '======DECLARE VARIABLES====
> BT VAR BYTE(9)
> KP VAR NIB(4)
> DIGIT VAR NIB
> SCAN VAR NIB
>
> DIGIT = 1
>
> LOOP: 'GRAB 4 KEY PRESSES FROM PINS 0 - 9
> FOR SCAN = 0 TO 9
> BUTTON SCAN,1,255,250,BT(SCAN),0,NOPRESS
> KP(DIGIT)=SCAN
> DEBUG "KEY PRESSED = "
> DEBUG DEC KP(DIGIT),CR
> DEBUG "DIGIT = "
> DEBUG DEC DIGIT, CR, CR
> DIGIT = DIGIT + 1
> IF DIGIT > 4 THEN RESULT
>
> GOTO LOOP
>
> NOPRESS:
> NEXT
> GOTO LOOP
>
> RESULT:
> DEBUG "RESULT--> "
> FOR SCAN = 1 TO 4
> DEBUG DEC KP(SCAN)
> NEXT
> DEBUG CR,"
",CR
> DIGIT = 1
> GOTO LOOP
>
>
> I know the keypad is connected properly because the "KEY PRESSED"
> debug displays the proper key that I hit (usually). I have the
keypad
> connected properly per the "BUTTON" command.
>
> HERE ARE SOME OTHER RESULTS FROM TESTS:
>
> Entering 9876 returns result 0877
> 1234 returns 0235
> 6789 returns 157810!
> 2345 returns 0346
> 5555 returns 0556
>
> Also 1111, 2222, 3333 or any keypad input combination of 1-2-3 never
> shows a "RESULT" on the screen, as the DIGIT variable gets to 3 then
> is re-set to 1 somehow.
>
> I am sure I am doing something wrong with variables or arrays, but
> have been at this for days now and am completely stuck! I hope
> someone can look at my code, or even run it on their own stamp, and
> shed some light on the problem(s) with my logic!
>
> Thanks for the insight! Brian Dalziel - Milwaukee, WI USA
Okay, Steve P. corrected my BT array problem by noticing it should be
BT(10) , thanks Steve!. Now the first digit in the "RESULT" matches
the key pressed. Stuff still going on:
Entering 1234 returns result 1235
2345 returns 2346
9876 returns 9877
6789 returns 67810
Problem with 1-2-3 keys still exists exactly as before, DIGIT variable
never reaches 4 with no result returned. [noparse]:)[/noparse]
and NIB(5), not 100% sure why the NIb must go up to 5, but the thing
works now. Thanks for everyone's input..........
--- In basicstamps@y..., "signaltech_99" <bdalziel@e...> wrote:
> --- In basicstamps@y..., "signaltech_99" <bdalziel@e...> wrote:
> > Hi Everyone,
> >
> > This is my first shot at programming a stamp. I have connected to
> > pins 0-9 a very simple keypad which fires the appropriate pin for
> > numbers 0 - 9. This part seems to be working well enough.
> >
> > I am building a 100 disc CD jukebox that needs to get a 4-digit
> input
> > from the keypad like 4502 (which would later extract 45 for the
disc
> #
> > and 02 for the track #, then pulse the changer's disc-up and
> track-up
> > buttons thru an optoisolator).
> >
> > The proper DEBUG result of this test program for an input of 4502
> > should be this:
> >
> > KEY PRESSED = 4
> > DIGIT = 1
> > KEY PRESSED = 5
> > DIGIT = 2
> > KEY PRESSED = 0
> > DIGIT = 3
> > KEY PRESSED = 2
> > DIGIT = 4
> >
> > RESULT = 4502
> >
> > Right now it actually comes back with:
> >
> > KEY PRESSED = 4
> > DIGIT = 1
> > KEY PRESSED = 5
> > DIGIT = 2
> > KEY PRESSED = 0
> > DIGIT = 3
> > KEY PRESSED = 5
> > DIGIT = 2
> >
> > [noparse][[/noparse]NO RESULT DISPLAYED!]
> >
> > Here is the code thus far:
> > '{$STAMP BS2}
> > '======DECLARE VARIABLES====
> > BT VAR BYTE(9)
> > KP VAR NIB(4)
> > DIGIT VAR NIB
> > SCAN VAR NIB
> >
> > DIGIT = 1
> >
> > LOOP: 'GRAB 4 KEY PRESSES FROM PINS 0 - 9
> > FOR SCAN = 0 TO 9
> > BUTTON SCAN,1,255,250,BT(SCAN),0,NOPRESS
> > KP(DIGIT)=SCAN
> > DEBUG "KEY PRESSED = "
> > DEBUG DEC KP(DIGIT),CR
> > DEBUG "DIGIT = "
> > DEBUG DEC DIGIT, CR, CR
> > DIGIT = DIGIT + 1
> > IF DIGIT > 4 THEN RESULT
> >
> > GOTO LOOP
> >
> > NOPRESS:
> > NEXT
> > GOTO LOOP
> >
> > RESULT:
> > DEBUG "RESULT--> "
> > FOR SCAN = 1 TO 4
> > DEBUG DEC KP(SCAN)
> > NEXT
> > DEBUG CR,"
",CR
> > DIGIT = 1
> > GOTO LOOP
> >
> >
> > I know the keypad is connected properly because the "KEY PRESSED"
> > debug displays the proper key that I hit (usually). I have the
> keypad
> > connected properly per the "BUTTON" command.
> >
> > HERE ARE SOME OTHER RESULTS FROM TESTS:
> >
> > Entering 9876 returns result 0877
> > 1234 returns 0235
> > 6789 returns 157810!
> > 2345 returns 0346
> > 5555 returns 0556
> >
> > Also 1111, 2222, 3333 or any keypad input combination of 1-2-3
never
> > shows a "RESULT" on the screen, as the DIGIT variable gets to 3
then
> > is re-set to 1 somehow.
> >
> > I am sure I am doing something wrong with variables or arrays, but
> > have been at this for days now and am completely stuck! I hope
> > someone can look at my code, or even run it on their own stamp,
and
> > shed some light on the problem(s) with my logic!
> >
> > Thanks for the insight! Brian Dalziel - Milwaukee, WI USA
>
>
>
> Okay, Steve P. corrected my BT array problem by noticing it should
be
> BT(10) , thanks Steve!. Now the first digit in the "RESULT" matches
> the key pressed. Stuff still going on:
>
> Entering 1234 returns result 1235
> 2345 returns 2346
> 9876 returns 9877
> 6789 returns 67810
>
> Problem with 1-2-3 keys still exists exactly as before, DIGIT
variable
> never reaches 4 with no result returned. [noparse]:)[/noparse]
>PROBLEM SOLVED! Prob was with BOTH of my arrays, should be BYTE(10)
>and NIB(5), not 100% sure why the NIb must go up to 5, but the thing
>works now. Thanks for everyone's input..........
>
>What you may be missing is that arrays BEGIN with element numbered ZERO.