Shop OBEX P1 Docs P2 Docs Learn Events
how to program a number pad — Parallax Forums

how to program a number pad

the_0utsider1the_0utsider1 Posts: 13
edited 2013-01-31 12:30 in BASIC Stamp
I am building a keypad with binary output.
ex: pins 0-3 = low(voltage),high,high,low = 6
I need to take this input and use it as the number and not just a character.
How might i program this?

TIA

Comments

  • FranklinFranklin Posts: 4,747
    edited 2013-01-31 12:16
    Have you been able to get any input into your program yet? Tje pins can be read as a binary number if they are in sequence (see ina) then your program can do the conversion. Show us the code you are running now and perhaps we can tweak it for you.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-31 12:30
    I don't understand what you're asking. You have a keypad and you're already doing the scanning of the keypad and the conversion of a keypress to a 4-bit binary value. Do you want to make up a 16-bit number from a series of keypresses or what?

    Typically you have a variable that's initialized to zero. For each digit that's entered, you do: variable = variable * 10 + digit

    If you want to do this correctly, you also check for out-of-range. For example, when a new digit is entered, the previous variable value must be less than 6553. If it's equal to 6553, then the new digit must be less than 6. You want to check for a correction. Often for a 3 x 4 keypad, the "*" is used to discard the last digit entered by doing: variable = variable / 10. Obviously, if all of the digits get discarded, the variable will become zero which is what you want. Typically, the "#" key is used to enter the number into the program and continue with the program.
Sign In or Register to comment.