Can someone help me understand what is going on here. I am receiving serial data in the format “angle,sonar distance,ir distance.”. My code works with the first 2 variables. I am trying to add the third. I do not understand the syntax for this code. Do I need an index2 or index1+1? what is the proper method?
/////////////////////////////////////////////////// index1 = val.indexOf(","); // find the character ',' and puts it into the variable "index1" angle= val.substring(0, index1); // read the val from position "0" to position of the variable index1 or thats the value of the angle the Arduino Board sent into the Serial Port sonar_distance= val.substring(index1+1, val.length()); // read the val from position "index1" to the end of the val pr thats the value of the distance //ir_distance= val.substring(index2+1, val.length()); // converts the String variables into Integer iAngle = int(angle); isonar_distance = int(sonar_distance); }