Dear friends,
I am looking for a clever way to “parse” strings from terminal, as user input, to activate functions and actions in my sketch.
I am not experienced in this field so I asking you, that have great ideas, for good suggestions.
To make more clear, what I need to do is a good way to get the users typing at the terminal widget and then, according to the entered text, to execute whatever needed as functions or a bunch of commands etc.
yes, for sure I have…
Also I have expanded some how see me code snippet:
BLYNK_WRITE(V??)
{
/// take "commands" from the terminal and acting accordingly ///
/// https://www.arduino.cc/en/Tutorial/StringSubstring ///
/// (stringOne.equalsIgnoreCase(stringTwo)) ///
/// stringOne.trim(); ///
/// int strgLenght = param.getLength(); /// get the string lenght ///
String getString = param.asStr(); /// get the string ///
getString.trim(); /// cut off the blank spece(s) at the end of the string ///
/// terminal.print("String Lenght= ") ;
/// terminal.println(strgLenght);
/// getString.toUpperCase(); /// convert all string characters to uppercase ///
if (getString.equalsIgnoreCase("Marco")) {
terminal.println("You said: Marco") ;
terminal.println("I said: Polo") ;
} else if (getString.equalsIgnoreCase("Clear")) {
terminal.println("You said: clear , OK I will !") ;
lcd.clear();
terminal.println();
terminal.println();
terminal.println();
terminal.println();
terminal.println();
terminal.println();
terminal.println();
terminal.flush();
} else if (getString.equalsIgnoreCase("Startled")) {
terminal.println("You said: startled , OK I will !") ;
ledBlink = true;
but I am looking for an easy general, clever way to to it
to have let say 20-30 keywords that if the user write them (one at a time) at the terminal, the parsing of the terminal input to be able to execute various functions etc.
I don’t like to implement this using a pile of
if(bla bla)
/// call the specific function ///
else if(thisthis)
/// call the specific function ///
etc etc etc
I thought about case but I don’t know how to associate keywords with numbers in a way as 1:clear , 2:runme , 3:functionZero etc so If I get the keyword ex functionZero to execute case 3
Is it possible to implement something like this???
@mikekgr on this occasion a big list of if, else if statements is probably the best way.
You can use Arduino’s startsWith() function so users don’t have to type in full words etc. Ensuring you keep the keywords unique for startsWith().
If you have 20+ keywords I don’t think allocating numbers will be user friendly.