Skip to content

Instantly share code, notes, and snippets.

@whichlight
Created November 11, 2013 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whichlight/7416081 to your computer and use it in GitHub Desktop.
Save whichlight/7416081 to your computer and use it in GitHub Desktop.
serial reading arduino, semicolon between each measurement (like newlines) and comma between vals of each measurement. ex: x1,y1,c1;x2,y2,c2
if (Serial.available() > 0) {
// get incoming byte:
byteRead = Serial.read();
/*Listen for a comma which equals byte code # 44 */
if(byteRead==44){
data[counter] = String(serialDataIn);
serialDataIn = String("");
counter = counter + 1;
}
else if(byteRead == 59){
data[counter] = String(serialDataIn);
serialDataIn = String("");
counter = 0;
x = data[0].toInt();
y = data[1].toInt();
c = data[2].toInt();
Serial.print("x :");
Serial.print(x);
Serial.print(" y :");
Serial.print(y);
Serial.print(" c :");
Serial.println(c);
}else{
serialDataIn += (char)byteRead;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment