how to program a number pad
the_0utsider1
Posts: 13
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
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
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.