Problem attempting to create serial input function
Posted: Sat Aug 08, 2015 5:51 pm
Hello,
I have been atempting to create a function that will listen for serial input and then compare that input against a list of commands.
It seems to work but it keeps looping and presenting the prompt.
Am i missing some thing?
I have been atempting to create a function that will listen for serial input and then compare that input against a list of commands.
It seems to work but it keeps looping and presenting the prompt.
Am i missing some thing?
Code: Select all
void loop()
{
String CommandToRun;
CommandToRun = getSerialInput();
if (CommandToRun == "run")
{
Serial.println("Command received\n");
}
}
String getSerialInput()
{
Serial.println("\n>");
String someInput;
while (Serial.available() > 0)
{
delay(10);
char recieved = Serial.read();
// Process message when new line character is recieved
if (recieved == '\n')
{
Serial.println(someInput);
return someInput;
}
someInput += recieved;
}
}