Pulling data from a text document and outputting functions

Maybe im thinking of this in to much of a MATLAB sense. I am looking to see what happens when I get the serial data, if its even coming in correctly. I dont know how to phrase this good. Im wondering what output is happening, so I can tell my stepper motor do run a certain function. So if I have a L' it will call my 'turn90' function and turn my left stepper 90 degrees.

I also tried pasting that original text line (L,R,D',B,U,D,F',R,B',L',B2,R,F2,D2,F,L',U2,L,U2,L,B2,L',B2,L2,U2,L2,R2,U2,B2,U2) into the serial monitor to send to the arduino. Still not sure it worked. I put a unrecognized variable at the end, such as V, and nothing happened also.

Sorry if this is unclear, I am just confused.

Edit: Nevermind! its working fine, at least the serial monitor part. My sending isnt working that well. Also still unclear how to control things, but its a good start.

Also, do I need to verify this every time? or does it run in the background. Am I able to connect another thing to the same COM port?

So my view is that this is where learners should start from

Arduino CC does not agree with you.
The string reference page does not include any text processing methods. Instead it refers beginners to the String page for text processing functions. That is as it should be. Arduino CC recognized the complexity of c-string methods for beginners and opted to promote Strings instead.

bigolstussy:
.
Edit: Nevermind! its working fine, at least the serial monitor part. My sending isnt working that well. Also still unclear how to control things, but its a good start.

Also, do I need to verify this every time? or does it run in the background. Am I able to connect another thing to the same COM port?

not sure which code you use. The one I had posted included printing the grouped command line Serial.print(F("\nparsing : ")); Serial.println(receivedChars);and then this input is split into commands and findAndExecute() function is calledd with its specific command as a parameter.

what do you want to verify? If you want to ensure what was received is what you sent, you need to add extra information in what you send (like a CRC or checksum).

there is only one thing connected to the COM port which is sending stuff to the arduino. The arduino will wait for a command line to arrive, deal with it (which can take time depending on what you do with motors) and then listen again for the next command line.

@drmpf... what to say... the documentation for Serial offers Serial.readStringUntil(). Why didn’t you use it? The documentation for & only talks about pointers and does not discuss the passing by reference you (very rightly) insist on... so does it mean it does not exist or that’s not what they "recommend"?...

Serial.readStringUntil()

That falls into the don't have delays in the loop(), which I think we both agree on.

We also agree on the pass Strings instances by reference.

Your very own library uses extensively cStrings operations and is not in arduino documentation... so not recommended by arduino.cc, thus don’t use it?

The point is: what is or is not in the documentation does not reflect always capabilities you need to use or on the opposite should use. There are also tons of half baked or poor legacy stuff in there too...

My take is explore and learn and understand fundamentals. Only then you understand implications, constraints, technical debt etc and use your brain to pick one right tool at the right time.

Sorry for not replying sooner, I just got done with a series of tests. They went "well". I dont think I have to verify anything anymore. I just need to change up some of the code. I used the code you made J-M-L for a example. Lets say I wanted to do a certain function, such as calling my Turn90 function. Could I adjust this line?

void func_L(const char* s)  {Serial.print(F("in Function ")); Serial.println(s);}

and replace the Serial.print part with Turn90 function.

Basically, Im not sure where I can call my function to turn the stepper motor when it receives the input letters(L, R, U, L'...)

The keys array is an array of struct

 keys[] = {
  {"L", func_L},
  {"R", func_R},
  {"D'", Dunc_Dp},
  {"B2", func_B2},
  {"U2", func_U2},
  {"SHARED1", func_SHARED},
  {"SHARED2", func_SHARED}
};

each struct maps a name (in between double quotes) to a function name

 struct {
  const char* label;
  void (*func)(const char*);
}

So you can directly attach the command to the Turn90() function by having {"L", Turn90} in the array.

The only catch is that I decided to have the function take a parameter (the command recognized to trigger the function). The idea is that you could have the same function attached to various commands and move into the function some intelligence to do something different based on the exact command.

so you would have to either modify the struct declaration to remove the need for a param to the function

 struct {
  const char* label;
  void (*func)();
}

and remove the command when I call the function

 if (!strcmp(s, keys[i].label)) {
      keys[i].func(); // <== no parameter
      success = true;
      break;
    }

or just define your Turn90 function with a parameter

void Turn90(const char* s)
{
  ...
}

To take a parameter

Wow, got it to work like I wanted. I want to thank you for teaching me a whole bunch about Arudino coding! Cheers!

Great news!