Shop OBEX P1 Docs P2 Docs Learn Events
number problem — Parallax Forums

number problem

ArchiverArchiver Posts: 46,084
edited 2000-07-19 21:37 in General Discussion
The classic way to do this:

Sorta-code:



numval = 0
more:
key = readkey() ' return 0-9
if {ENDCONDITION} then done
numval=numval*10+key
goto more

done:

Tracy might comment if it is worth considering define y=x*10 as
y=(x<<3)+(x<<1)

{ENDCONDITION} is probably an enter key. However, if you want, say 3 digits,
you can change it a little:

numval=0
digcount=0
more:
key=readkey()
digcount=digcount+1
numval=numval*10+key
if digcount<>3 then more


The readkey routine will depend on how your keys are wired up.

You can use a numeric keypad with a PAK-VI, or wire up 10 or 11 switches to
separate I/O. You can also use a row/column scanning technique or resistors
to put a large number of switches on a single pin (my book Microcontroller
Projects with Basic Stamps covers both of these methods). There are several
other keypad controller devices out there too.

Regards,

Al Williams
AWC
* Pulse input and output with the PAK-VII and PAK-VIII:
http://www.al-williams.com/awce


>
Original Message
> From: Pieter-Jan van Diepen [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=R2nqxVugG1vyROewoJIMwc5HzPON8QScLSrZzj1WjTfSMih9thKBLwExXh84wRWwMv3jKSNHZpVF45Ml]diepenpj@h...[/url
> Sent: Wednesday, July 19, 2000 12:37 PM
> To: basicstamps@egroups.com
> Subject: [noparse][[/noparse]basicstamps] number problem
>
>
> A problem:
>
> I have 10 switches, 0 THRU 9. What i want to do is if i press
> '1', '3', '9'
> for example, that a bs2 converts it to a value 139 etcetera
> Perhaps somebody
> has written some code for that?
>
> thanks!!
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>
>
>

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-07-19 21:37
    A problem:

    I have 10 switches, 0 THRU 9. What i want to do is if i press '1', '3', '9'
    for example, that a bs2 converts it to a value 139 etcetera Perhaps somebody
    has written some code for that?

    thanks!!
    ________________________________________________________________________
    Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
Sign In or Register to comment.