-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_writer.pde
45 lines (37 loc) · 1.02 KB
/
print_writer.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.*;
import java.util.Locale;
import processing.serial.*;
// Instantiating serial and print writer
Serial mySerial;
PrintWriter output;
void setup() {
println("Inside setup");
mySerial = new Serial(this, Serial.list()[2], 9600);
String filename = "/Users/harshdeep/EPFL/igem_2020/data.txt";
File f = new File(dataPath(filename));
// Delete the file if already exists
if (f.exists())
{
println("file exists");
f.delete();
}
try {
output = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)));;
} catch(IOException e) {}
}
void draw() {
if (mySerial.available() > 0 ) {
String value = mySerial.readString();
if ( value != null ) {
println(value);
output.println( value );
}
}
}
void keyPressed() {
println("Closing the application");
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
println("Exiting the program");
exit(); // Stops the program
}