We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › loadStrings from output txt
Page Index Toggle Pages: 1
loadStrings from output txt (Read 349 times)
loadStrings from output txt
Jan 27th, 2008, 9:38pm
 
hello all!

i am fairly new to processing and my programming skills lack to go any further on this without your help.

so, thing is: i am retrieving data from a website (http://www.iraqbodycount.org/database), which causes a sewing machine connected to an arduino, to do one stitch per dot (".") - for each reported case of death.

this is as far is i got:

------------------------------------------------------------
import processing.serial.*;
import prohtml.*;

HtmlList htmlList;
Serial myPort;
PrintWriter output;

String URL = "http://www.iraqbodycount.org/database";
String tempstring;
int range;

void setup(){
 size(100,100);
 htmlList = new HtmlList(URL);
 output = createWriter("range.txt");
 //myPort = new Serial(this, Serial.list()[1], 19200);
 }

void draw(){
 for (int i=0; i<htmlList.pageList.size(); i++){
   String ts = htmlList.pageList.get(i).toString();
   int t = ts.indexOf("ibc-range");  
   if(t > -1){
   tempstring = htmlList.pageList.get(i+3).toString();
   }
 }
 
 range = int(tempstring.substring(0,5)); //
 println(range);

 for (int i=1; i<=range; i++)
 {
   println(".");
   println(((range-i)-range)*(-1));
   output.flush();
   output.println(((range-i)-range)*(-1));
   //myPort.write(".");
   delay(1000);
   }
}


my problems:

- my draw function loops continuously. it should stop, as it reaches the current state, which is 88100, and just add +1 each time as the counter is updated.

- i need an output file, on how many stitches are already done. my solution, the PrintWriter output, won't work i think, cause each time the program runs, the file would be created once again. how should i do that?

- then i need to import the data from that file and turn it into a variable, "cnt", which holds the information, on how many stitches are done so far. - by loadStrings?

- it would replace the i in the for loop with (i=cnt; i<=range; i++). but how would i uptade "cnt" after the loop?

- what then leads me back to the output file and how it should be created.

that's it. i know, there's quite a lot i don't know, but any comment on how to get this run properly, would be very very much appreciated.

very thanks in advance.
lowell.
Re: loadStrings from output txt
Reply #1 - Jan 28th, 2008, 6:13am
 
If I understand well, you want your program to check how many cases were reported since the last time it has been run, right?

Quote:
my draw function loops continuously

That is the purpose of the draw method. If you want your code to execute only once, call noLoop() in setup().

Quote:
i need an output file, on how many stitches are already done.

Then I suggest you do what you have planned, save the number of stitches somewhere in an output file.
Code:
PrintWriter output;
output = createWriter("stitches.txt");
output.println(numberOfStitches);
output.flush();
output.close();


To retrieve the variable at beginning, loadStrings() is indeed the solution :
Code:
String lines[] = loadStrings("stitches.txt");
int stitches = int(lines[0]);
println(stitches + " stitches");
Page Index Toggle Pages: 1