I want to pass commands to the arduino from a pc and then get the arduino to perform actions based on the command
i have written some code but it sometimes seems to not work
here is an example
while (Serial.available())
{
InChr= Serial.read(); //gets one byte from serial buffer
if (InChr == '%')
{
break;
} //breaks out of capture loop to print readstring
InStr += InChr ;
}
if (InStr == "Reset")
{
Serial.println("Reset Counter = 0");
N = 0 ;
InStr = "" ;
}
if (InStr.substring(0,5) == "Start")
{
//InStr = InStr.trim() ;
InStr = InStr.substring(5,(InStr.length() + 1 )) ;
Serial.println(InStr) ;
//-------------------
char buff[32]="";
InStr.toCharArray(buff,sizeof(buff));
buff[ sizeof(buff) / sizeof(buff[0]) - 1 ]='\0'; // I always like to null terminate strings just in case
TargetSpeed = atof(buff);
//-------------------
Serial.print("Start Process - ") ;
InStr = "" ;
LoadOn = false ;
ManLoad = false ;
}
I send it a command for example "Start%"
it seems to work first time you send it always, but sometimes it does nothing
is there some standard tried and trusted code for reading the serial port i can use ?