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: