Keypad input in Switch Case

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;
}

The structure of your several switch statements is very odd.

But the above line uses = where == would make more sense.

a7

Similar problem here

while (ModeInt = 1) {

So you suggest changing all “=” for “==” ?
Okay i think it speed up the program for sure, thanks !
But Still
When i type one digit numbers everything is okay.
When I type two digit ( for example 35 → 5 gets stored in some way)
Because after i type “1” it gives me 15
If I type 22 and after I type 5 it will give me 52…

No, we suggest you learn the difference between the two, and how an if statement works, and where you should use one or the other (=, ==) as needed.

a7

Your FSM is a little bit unlikey desigend. Avoid while() instructions inside and instead add some addtional stages into the FSM to get the required funcionality.

Then there’s this:

 boolean CommandEntered = false;

https://cboard.cprogramming.com/c-programming/109187-declare-variable-case-statement.html