Created
November 11, 2013 16:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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