#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 25, 35, 33, 29 };
byte colPins[COLS] = { 27, 23, 31 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
}
char charGain[4];
int charindex =0;
int i;
void loop(){
for(charindex == 0;charindex < 3; charindex++){
char key = kpd.getKey();
if (key != NO_KEY){
if (key = '#'){
for(charindex;charindex < 3;charindex++){ //if the user didn't enter 4 digits float from the keypad, then other char in the array is set to be 0
charGain[charindex]=0;
}
charindex=0;
}
else if (key = '*'){
int 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]);
}
}
}
charGain[4] = '\0';
i = atoi (charGain);
Serial.print(i);
}
Can anyone tell me what's wrong here?