Loading...
Logo
Processing Forum

Save TXT

in Core Library Questions  •  1 year ago  
Hello
I'm   trying to record   values   ​​coming from a   temperature sensor   in a document .   TXT   but the   code   I'm using   does not   write anything   ..

thanks

Copy code
  1. import processing.serial.*;

  2. Serial port;
  3. PrintWriter output;

  4. void setup() {
  5.   // Open the port that the board is connected to and use the same speed
  6.   port = new Serial(this, "COM11", 9600);  

  7.   // file to store your incoming data
  8.   output = createWriter("teste.txt"); 
  9. }

  10. void draw() {
  11.   background(255);
  12.   if (0 < port.available()) {
  13.     // read it and store it in val
  14.     char val = (char)port.read();         
  15.     output.print(val);
  16.     print(val);
  17.   }
  18. }

  19. void stop(){
  20.   // Writes the remaining data to the file
  21.   // and closes it before closing sketch
  22.   output.flush(); 
  23.   output.close();
  24.   println("Data Saved");
  25.   super.stop();
  26. }

Replies(4)

Re: Save TXT

1 year ago
it seems like stop() is not called on quitting the sketch.
try defining a key stroke like ESC that does the saving and quitting:


Copy code
  1. import processing.serial.*;

  2. Serial port;
  3. PrintWriter output;

  4. void setup() {
  5.   // Open the port that the board is connected to and use the same speed
  6.   port = new Serial(this, "COM11", 9600);  

  7.   // file to store your incoming data
  8.   output = createWriter("teste.txt"); 
  9. }

  10. void draw() {
  11.   background(255);
  12.   if (0 < port.available()) {
  13.     // read it and store it in val
  14.     char val = (char)port.read();         
  15.     output.print(val);
  16.     print(val);
  17.   }
  18. }

  19. void keyPressed() {
  20.   if (key == ESC) {
  21.     stop();
  22.     exit();
  23.   }
  24. }

  25. void stop(){
  26.   // Writes the remaining data to the file
  27.   // and closes it before closing sketch
  28.   output.flush(); 
  29.   output.close();
  30.   println("Data Saved");
  31.   super.stop();
  32. }

Re: Save TXT

1 year ago
Thanks  M aleo

Re: Save TXT

3 months ago
How you can insert Date, and Time to the document txt?? :|

Re: Save TXT

3 months ago
I use this:
http://processing.org/reference/nf_.html

Age = int (year() + nf(month(),2) + nf(day(),2) + nf(hour(),2) + nf(minute(),2) + nf(second(),2));

Then

output.print(Age);

?