This is the keypad I used as input.
For the following code, I would like to store values '1' and '2' into the empty array when I pressed '1' and '2' at the keypad.
The current problem I had is, the value both '1' and '2' not coming to the array. And the value of the arrayIndex always give me "1".
Here is the result. When I press 'star' it shows 'star' and '0'. After I press five '1', I pressed '7' to see whether the value of arrayIndex changed or not. But the code is not working as expected. Can you please explain why is not working and what causes the problem?
How are you reading the keypad? Post all your code.
If you are using a library does it support returning multiple values if more than 1 key is pressed? It obviously can't return multiple values in a single variable (customKey).
The first if statement tests for customKey equal to * , and the remainder of the code is only executed when this is true. The value of customKey does not change until you read the keypad again, so it can never be 1, 2, or any other value than *
You are testing for customKey being equal to 1 and 2 at the same time, which is impossible.
theArray and arrayIndex are declared as local variables, that will cease to exist at the end of the if statement.
This is the equivalent code that results when the parts that can never be executed are removed:
It is the character code for the digit zero. The characters '0' through '9' are together in order in ASCII so subtracting the character code for zero from a digit character ('0' through '9') gives you the digit's decimal value. '0' - '0' is 0, '1' - '0' is 1, '2' - '0' is 2, etc.