Shop OBEX P1 Docs P2 Docs Learn Events
Please help! This should be simple! — Parallax Forums

Please help! This should be simple!

ArchiverArchiver Posts: 46,084
edited 2002-03-24 02:53 in General Discussion
Please try to help me! I have a very basic keypad connected to my
stamp such that common is VDD and each button 0-9 is connected to the
cooresponding input pin 0-9. I am seeing the key presses just fine.

The problem is "PASS" never increments in my program, preventing the
brach to RESULT. Does anyone know why this would be happening?

THANKS VERY MUCH IN ADVANCE,
Brian Dalziel


'{$STAMP BS2}


'======DECLARE VARIABLES====
BT VAR BYTE(9)
KS VAR NIB
PASS VAR NIB
SCAN VAR NIB

PASS = 1

LOOP:
For SCAN = 0 to 9 'scan each pin
BUTTON SCAN,1,255,250,BT(SCAN),0,JUMP
GOSUB ASSIGN
IF PASS = 5 THEN RESULT
GOTO LOOP

JUMP:
NEXT
GOTO LOOP

ASSIGN:
KS(PASS)=SCAN
DEBUG "PRESSED = "
DEBUG DEC KS(PASS),CR
PASS = PASS + 1
DEBUG "PASS = "
DEBUG DEC PASS, CR, CR
RETURN

RESULT:
DEBUG "RESULT--> "
FOR SCAN = 1 TO 4
DEBUG DEC KS(SCAN)
NEXT
END

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-03-24 00:30
    > Change your NIB variables to BYTE variables. As NIB variable they can only
    > contain the values from 0-7 inclusive.

    Hey Bruce, are you sure?

    A nibble is 4 bits, which allows 16 combinations (0 to 15, (or 0 to F hex)).

    0000 =0
    0001 =1
    0010 =2
    0011 =3
    0100 =4
    0101 =5
    0110 =6
    0111 =7
    1000 =8
    1001 =9
    1010 =10
    1011 =11
    1100 =12
    1101 =13
    1110 =14
    1111 =15


    Cheers,

    Ben.
    --
    http://www.lennard.net.nz/
    Ben Lennard, NCEE, Dip EE

    Web Hosting and Electronics R&D
    Club Coordinator, Victoria University of Wellington Hockey Club

    Hm: +64 4 972 7567
    Mb: +64 21 536 627
    87 Spencer Street
    Crofton Downs
    Wellington
    New Zealand

    "To the optimist, the glass is half full. To the pessimist, the glass is
    half empty. To the engineer, the glass is twice as big as it needs to be."

    No animals were harmed in the transmission of this email, although the
    Dog next door is living on borrowed time, let me tell you! Those of you
    with an overwhelming fear of the unknown will be gratified to learn that
    there is no hidden message revealed by reading this warning backwards.




    >From: Bruce Bates <bvbates@u...>
    >To: basicstamps@yahoogroups.com
    >Subject: Re: [noparse][[/noparse]basicstamps] PLEASE HELP! THIS SHOULD BE SIMPLE!
    >Date: Sun, 24 Mar 2002 7:08 AM
    >

    > At 06:56 PM 3/23/2002 +0000, you wrote:
    >>Please try to help me! I have a very basic keypad connected to my
    >>stamp such that common is VDD and each button 0-9 is connected to the
    >>cooresponding input pin 0-9. I am seeing the key presses just fine.
    >>
    >>The problem is "PASS" never increments in my program, preventing the
    >>brach to RESULT. Does anyone know why this would be happening?
    >>
    >>THANKS VERY MUCH IN ADVANCE,
    >>Brian Dalziel
    > Brian -
    >
    > Change your NIB variables to BYTE variables. As NIB variable they can only
    > contain the values from 0-7 inclusive.
    >
    > There is probably more to the problem, but that is a start.
    >
    > Regards,
    >
    > Bruce Bates
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and
    > Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-24 01:00
    At 12:30 PM 3/24/2002 +1200, you wrote:
    > > Change your NIB variables to BYTE variables. As NIB variable they can only
    > > contain the values from 0-7 inclusive.
    >
    >Hey Bruce, are you sure?

    My apologies Ben, to you and the list. I sent that reply out too quickly.
    A NIB can contain the values 0-15 inclusive.

    I was able to delete the message from the Yahoo Groups list, but it
    apparently did get out to some folks before the delete took effect.
    Sorry for the confusion

    Bruce
  • ArchiverArchiver Posts: 46,084
    edited 2002-03-24 02:53
    Brian-

    You're using a NIB array for KS without declaring same. As a
    result, writing to KS(1) overwrites PASS, writing to KS(2)
    overwrites SCAN, etc.

    In addition, you've made the BT byte array length 9, but you're
    using 10 elements when BT(SCAN) goes from 0 to 9.

    If all you mean to do is test for high or low on the pins, you may
    wish to test the level at the pin more directly:

    KS(PASS) = IN0(PASS)


    Regards,

    Steve

    signaltech_99 wrote:

    > ...The problem is "PASS" never increments in my program,
    > preventing the brach to RESULT.
Sign In or Register to comment.