Passing Function over Serial or Console

So I am building a robot type object with motors etc. I got past a few of my other issues and can control it pretty reliably. With this I wrote a few functions to deal with straight, rotate and turn (example is below). The function controls the power over PWM and the delay. So if I want the bot to rotate in a right direction at full speed for 5 seconds I can put funcRotate(5000, 54, 214). My question is is there a way that in either the serial view on the Uno/Mega or the console on the Yun, can I type just that and have it pass that function into the loop? OR what would be the best method to be able to control all of these aspects over serial/console. I would like to avoid using a bunch of If/Thens if I can.
...

void funcRotate(unsigned int delayms, unsigned int powerWhite, unsigned int powerBlue){
  analogWrite(whiteOutPin, powerWhite);
  analogWrite(blueOutPin, powerBlue);
  analogWrite(brownOutPin, 133);
  analogWrite(yellowOutPin, 133);
  delay(delayms);
  analogWrite(whiteOutPin, 133);
  analogWrite(blueOutPin, 133);
  analogWrite(brownOutPin, 133);
  analogWrite(yellowOutPin, 133);  
}

can I type just that and have it pass that function into the loop?

You want to type "funcRotate(5000, 54, 214)", and have that function called with those values? No, you can't do that.

You'd need to collect the string, parse it, get the name "funcRotate", and 3 values (5000, 54, and 214), and call the function based on the name being what you expect:

   if(strcmp(funcToCall, "funcRotate") == 0)
      funcRotate(val1, val2, val3);

By the way, is it really necessary to add func to the name of the function? Is that so that you can recognize a function when it bites you in the ass?

Eh I was afraid of that. I will try that this weekend and report back. Thanks for the help.

By the way, is it really necessary to add func to the name of the function? Is that so that you can recognize a function when it bites you in the ass?

No not really necessary just a habit and pretty much yes that's why. :wink:

GunGeek:
Eh I was afraid of that. I will try that this weekend and report back.

It really is not that hard...
Here is a calculator that parses commands and accepts numerics from serial:
http://www.hackster.io/rayburne/scientific-calculator
http://www.instructables.com/id/Arduino-Scientific-Calculator/?ALLSTEPS
Ray

GunGeek:
Eh I was afraid of that. I will try that this weekend and report back. Thanks for the help.

By the way, is it really necessary to add func to the name of the function? Is that so that you can recognize a function when it bites you in the ass?

No not really necessary just a habit and pretty much yes that's why. :wink:

It's a whole lot easier when you code the commands to a single letter and/or use a state machine.