Here is my little project on using a 3*4 key pad. And I have to store what were entered by the user into an array and display them later.
I ues boarduino.
User is required to enter a maximum of 8 digits float including the radix point. Since there can be only one radix point in a float, so if the point is being pressed twice, it won't be shown. and the # is used to confirm after entering the number.
What I got from the program below is keep showing array [], the [] is actually a square(like when the arduino is not showing normal character). I am stuck with this, hope anyone could help. Thank you very much!!!
```
*#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'.','0','#'}
};
byte rowPins[ROWS] = {19, 18, 17, 16}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {15, 14, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
char charGain[9]; //this is the array use to store the total Gain, the maximum value is 1280, and I set 8 digits to store the gain, maximum 3 decimals
int charindex=0; //this is for the array index
int pointindex=0; //since there can be only one radix point '.' in a float, pointindex is set to record how many '.' are entered
//void enterGain(){ //block this sentence
void loop(){
keyArray();
printArray();
}
void keyArray(){ // function of storing what the user put in an array
// for(charindex = 0;charindex < 8; charindex++){
char key = keypad.getKey(); // get the key from keypad
if (key != NO_KEY){ //if there is any key being put
if (key = '.'){ //if the radix point is pressed for once, display the '.'
pointindex++;
if (pointindex=1){
charGain[charindex]=key;
charindex++;
Serial.print(charGain[charindex],BYTE);
}
else{ //if the radix point is pressed for more than once, do not display the '.', but display hwo many times are pressed
pointindex++;
Serial.print("pointindex");
Serial.print(pointindex);
}
}
else if (key = '#'){ // if # being pressed, this is for the user to confirm whether the number is what he want
// Serial.println('Are you sure about your enter? Press # for sure, press 0 for re-enter');
// confirm_or_enter();
for(charindex;charindex < 7;charindex++){ //if the user didn't enter 8 digits float from the keypad, then other char in the array is set to be 0
charGain[charindex]=0;
pointindex=0;
charindex=0;
}
}
else{ //if the user enter 0-9, then store it into array and display it
charGain[charindex]=key;
charindex++;
Serial.print(charGain[charindex],BYTE);
}
// }
charGain[8] = 0; //the last char in the array is set to be 0
// charGain[charindex]=0;
}
}
void printArray(){ //would like to show every char in the array after entering from keypad
for (charindex = 0;charindex < 9;charindex++){
//Serial.println("array [" ++ charindex ++ "]"++ charGain[charindex]);
Serial.print("array [");
delay (1000);
Serial.print(charindex);
delay (1000);
Serial.print("] ");
delay (1000);
Serial.println(charGain[charindex],BYTE);
delay (1000);
}
}*
```