Go Down

Topic: Board unexpectedly resetting (Read 699 times) previous topic - next topic

jestermaximus

realized I had an unnecessary for loop in there, but the result is the same.

Code: [Select]
void parseData(char input []){
  int currentBrightnessArray[] = {0,0,0};
  int returnCounter = 0;
  int currentNum = 0;
 
  //the loop looks for the delimiter and adds each digit (currently type char) into a substring,
  //which is turned into an int. then the space in the string is set to ' ' and trimmed off.
   
   char *currentSub = NULL;
   currentSub = strtok (input, ",");

   while (currentSub != NULL){
     currentBrightnessArray[returnCounter] = atoi(currentSub);
     currentSub = strtok (NULL, ",");
     returnCounter++;
   }
 
 
  //values of array are printed out.
  Serial.print("Output =");
  Serial.print(currentBrightnessArray[0]);
  Serial.print(", ");
  Serial.print(currentBrightnessArray[1]);
  Serial.print(", ");
  Serial.println(currentBrightnessArray[2]); 
}

dc42

strtok() expects its first argument to be a null-terminated string. Therefore, you need to add an extra null character at the end of 'output', or alternatively replace the final comma with a null character i.e. '\0'.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

jestermaximus

Ah ha! That solved the problem. Thank you. One final quick question: My output looks like this
Quote
se26, 100
setup
looping
Output =123, 226, 100
looping
Output =123, 226, 100
looping
Output =123, 226, 100


What is that being printed out at the top? Is that old data in the serial port or something (does that statement even make sense?  :smiley-roll-blue:).

Thanks,
Jester

dc42

Looks like old data in the PC serial buffer to me. What gets printed if you press the reset button on the Arduino?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up