Hello,
I use several inputs from 4x3 matrix keypad in my project. I type in ip etc. in void(setup) and eveything is just fine.
After i jump in loop(); the program is working like this:
I type in the number of command (for eg. '1" ,'2', '10'), I read the command translate it from char to int and it lands in switch(command) case.
Inside switch(command) it does some function once if the key is pressed.
Everything is okay when i type 1, 2, 3... 1, 1,1 it makes one command and it's ok.
BUT when i type for example 33 (wrong number - no command for that) it shows 33 and nothing happens - okay and after i type the right number for example 5 and it will show 35, after i type 2 it will show 25.
So it is for sure a problem with getting and saving the input from keypad.
The part of the code which is about the problem:
boolean listenCommand()
{
static byte indexMessage = 0;
boolean waitForIncomingMessage = true;
char c = membraneKeypad.getKey();
if (c >= '0' && c <= '9' ) {
Serial.print(c);
}
if (c != NO_KEY) {
if (c == endMarkerKey) {
message[indexMessage] = '\0'; // terminate the c-string
indexMessage = 0; // next time we will start fresh
waitForIncomingMessage = false;
} else if (indexMessage <= 1) command[indexMessage++] = (char) c; // save input if there is enough space in the buffer
}
return waitForIncomingMessage;
}
void loop() {
Ethernet.maintain();
switch (ModeInt) {
case 1:
while (ModeInt = 1) {
if (client.available()) {
char d = client.read();
Serial.print(d);
}
}
break;
case 2:
boolean CommandEntered = false;
while (!CommandEntered) {
if (! listenCommand()) {
commandInt = atoi(command);
Serial.println();
Serial.println(commandInt);
client.flush();
CommandEntered = true;
}
}
if (CommandEntered = true) {
switch (commandInt) {
case 3:
client.flush();
commandInt = 0;
client.write("MEASURE\x0d");
Serial.println("Pomiar wykonany");
delay(100);
while (client.available() > 0) {
int camretLen = client.available();
Serial.println("WYNIK");
for (int i = 0 ; i < camretLen; i++) {
char w = client.read();
Serial.print(w);
}
}
break;
}