Read string command from serial, can't declare variable for readString

I have this idea of writing a string of word in Serial, and after entering the word, it'll do some function inside, in this case, i named the function 'scanInput'.

The problem is that since i can't put readString inside the switch case, i have to put it inside the void loop and declare a variable to it. But i don't know how to declare it, since declaring it as either char, int, or long is wrong.

Is there any other method for this, or this is just one step?
Any help will be appreciated.

void loop() {

    Input = Serial.readString();

    switch (Input) {
      case "Frequency" :  {
        unsigned int freq = scanInput(26, "Freq =");
        Serial.println(freq);
      }
        break;
        
      case "Amplitude" :  {
        unsigned int amp = scanInput(35, "Amp  =");
        Serial.println(amp);
      }
        break;    
    }
  }

readString() - the function name is a clue to the data type required

I think a CASE statement only works with a number or a single character.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

UKHeliBob:
readString() - the function name is a clue to the data type required

Sorry, my bad.
i forgot there exists a string data type

Robin2:
I think a CASE statement only works with a number or a single character.

Yes, before this, i tried with single characters, and it works like a charm.

Robin2:
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data.

Ah, i didn't know this thread, thanks for telling me.

Sorry, my bad.
i forgot there exists a string data type

Don't confuse Strings (uppercase S), which are objects used with the functions of the String library and strings (lowercase s) which are zero terminated arrays of chars used with the C str* functions

In general, the latter are to be preferred in the small memory environment of the Arduino