Can't save data into CSV in the right place

edited March 2016 in Questions about Code

I am writing a function while the mouse is pressed, the timer will be record the exact time and save to a csv file during a specific time( the limit time of the mouse pressed is 10 times) While users are using the programme, it will keep going. (start again and again automatically)

I had done it successfully save to the right table. However, if users restart second times, the data of the second time will save in the wrong place and so on!

You can see that there is a blank about 10 rows in the B column.... I have no idea how to deal with this problem...

螢幕快照 2016-03-18 02.18.09

The code that I had written.....


void mousePressed() {

 if (mouseX > startBtnX && mouseX < startBtnX+startBtnW && mouseY > startBtnY && mouseY < startBtnY+startBtnH) {
   buttonPressed = true;
 }

 if (mouseButton == LEFT) { 
   println("timer started");
   mouseClicks++; 
   sw = new StopWatchTimer();
   sw.start();//store the current time 
  }

 if (mouseClicks == limit) { 
    saveTable(table, "data/data.csv");
    table.addColumn("id");
    sw.reset();
    mouseClicks = 0;
    //output.close();
    buttonPressed = false;

  }  

class StopWatchTimer {

TableRow newRow = table.addRow(); float ct = (currentTime/1000); String nct = ""+ct;

void start() { currentTime = millis() - startTime; println((currentTime/1000)-1); newRow.setString("id",nct);

} void reset() { currentTime = 0; startTime = millis(); println("timer started");

} }

Sign In or Register to comment.