Created
March 8, 2017 14:01
-
-
Save Thermoflux/a5948c5b2e93d5695b3c81fdc290966c to your computer and use it in GitHub Desktop.
Read Serial Data and save to txt file
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
import processing.serial.*; | |
Serial mySerial; | |
PrintWriter output; | |
void setup() { | |
mySerial = new Serial( this, Serial.list()[1], 9600 ); | |
println(Serial.list()); | |
output = createWriter( "data.txt" ); | |
} | |
void draw() { | |
if (mySerial.available() > 0 ) { | |
String value = mySerial.readStringUntil('\n'); | |
if ( value != null ) { | |
output.printf("%d/%d/%d %d:%d:%d ,",year(),month(),day(),hour(),minute(),second()); | |
output.println( value ); | |
} | |
} | |
} | |
void keyPressed() { | |
output.flush(); // Writes the remaining data to the file | |
output.close(); // Finishes the file | |
exit(); // Stops the program | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment