Corrected sample code for VR001

as the sample on the manual pages did not work for me.

On the web-page the plus character is not visible and the copied code does not even compile.
Printing the result lead in a hang of arduino.

I’ve corrected the code as follows, and verified it working with my mobile:

void getcommand (void)                   // This is the routine that listens and decodes any IR commands. Decodes commands end up in the global vars.
{ 
  int space1 = 0;
  int space2 = 0;
  
  if (Serial.available()) {
     Serial.print('*'); 
     rawcommand = Serial.readString();
     if (receivelog){
        Serial.println("START "  + rawcommand +  " END\r\nReceived string length = " + rawcommand.length() + "End character > at index = " + rawcommand.indexOf('>'));
     }

     //checking and deleting rubbish data at start of received command
     if ((rawcommand.indexOf('<') != 0) && (rawcommand.indexOf('<') != -1))
     {
        rawcommand.remove(0, rawcommand.indexOf('<'));
     }
     
     //check if received command is correct
     if ((rawcommand.charAt(0) == '<') && (rawcommand.indexOf('>') <= 12) && (rawcommand.indexOf('>') != -1) && (rawcommand.length() > 7))
     {
       if (receivelog){
         Serial.println("Command is VALID"); 
       }      
       //breakdown into chunks
       //command
       command = rawcommand.substring(1, 3);
       
       //finding the spaces to find the times and speedms
       for (int i=0; i <= rawcommand.length(); i++ )
       {
         if ((rawcommand.charAt(i) == ' ') && (space1 == 0))
         {
            space1 = i;
         }
         else if ((rawcommand.charAt(i) == ' ') && (space2 == 0))
         {
            space2 = i;
         }
       }

       //Setting the command variables and checking if they are indeed a number (toInt()).
       
       //times
       times = rawcommand.substring(space1 + 1, space2).toInt();
       
       //speedms
       speedms = rawcommand.substring(space2 + 1, rawcommand.indexOf('>')).toInt();

       if (receivelog){
         Serial.println("decoded commands are:");
         Serial.println("command = " + command);
         Serial.print("times = ");
         Serial.println(times, DEC);
         Serial.print("speedms = ");
         Serial.println(speedms, DEC);
       }
       
     }
     else
     {
       if (receivelog){
          Serial.println("Command is NOT valid");
       }
       resetserial();  
     }
  }
}

Hi

we’re aware there’s an issue with the + signs disapearing in the code.
We are working towards a solution

Best Regards,
VEL337

Very good sharing code,it can help me just now