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 › timer/stopwatch mouse start/stop - calc. problem
Pages: 1 2 
timer/stopwatch mouse start/stop - calc. problem (Read 4448 times)
Re: timer/stop watch mouse start and stop
Reply #15 - Aug 15th, 2009, 10:09am
 
Hi there!
I haven't tried your code, but I think one problem is that when you say you want to `pause` the clock, and you use noLoop() for that, it will not work. noLoop() is only stopping the code in the draw() to be executed, it does not stop the millis() from running, since the app itself is still running. You need a way to keep track of millis() regardless of how long it has run.

Pseudo code:
//
init:
TimeLapse = 0;
reset:
StartTime = millis();
running:
TimeLapse += millis() - StartTime();
pause: // do nothing ...
pauseEnd > goto reset;

Something like that ...
Re: timer/stop watch mouse start and stop
Reply #16 - Aug 15th, 2009, 12:46pm
 
can try the following code.. not very elegant but works like a normal stopwatch.. i didnt run it past the two minute mark b4 (no patience  Tongue).. not sure if there are any hidden bombs.. but see if it works for u..  Cheesy

Code:
int startSECOND, startMINUTE, startTOTAL;
int stopSECOND, stopMINUTE, stopTOTAL;
int dis_m,dis_s;
boolean startcount=false;
PFont font;

void setup()
{
 font=loadFont("AgencyFB-Reg-48.vlw");
 textFont(font, 50);
 size(300,150);smooth();
}

void draw()
{
 drawbuttons();
 
 if(mousePressed && rectSTART())
 {
   startSECOND=second();
   startMINUTE=minute();
   startTOTAL = startMINUTE*60 + startSECOND;
   startcount=true;
 }
 
 
 if(mousePressed && rectPAUSE())
 {
   if(startcount==true) startcount=false; else startcount=true;
 }
 
 
 if(mousePressed && rectSTOP())
 {
   startcount=false;
 }

   calculate();
   display();
 }

void drawbuttons()
{
 background(0);
 
 fill(#00FF28); rect(0,0,100,30);
 fill(#FF8000); rect(120,0,100,30);
 fill(#FF0D00); rect(240,0,50,30);
   
 fill(0); textFont(font, 20);
 text("START/RESET",10,25);
 text("PAUSE/RESUME",122,25);
 text("STOP",250,25);
 
}


boolean rectSTART()
{
 if(mouseX>=0&&mouseX<=100&&mouseY>=0&&mouseY<=30) return true;
 else return false;
}

boolean rectPAUSE()
{
 if(mouseX>=120&&mouseX<=220&&mouseY>=0&&mouseY<=30)  {return true;}
 else return false;
}

boolean rectSTOP()
{
if(mouseX>=240&&mouseX<=290&&mouseY>=0&&mouseY<=30)  {return true;}
 else return false;
 
}

void calculate()
{
 if(startcount)
   {
     stopMINUTE = minute();
     stopSECOND = second();
   
     stopTOTAL = stopMINUTE*60 + stopSECOND;
 
     int diff = stopTOTAL-startTOTAL;
     dis_m = diff/60;
     dis_s = diff - dis_m*60;
   }
}

void display()
{
 fill(#FFEA00);
 textFont(font,60);
 text(nf(dis_m,2)+":"+nf(dis_s,2), 80, 100);
}
Re: timer/stop watch mouse start and stop
Reply #17 - Aug 16th, 2009, 1:06am
 
Thanks a lot guys. I've finally got it to do exactly what I wanted.  For my project, I really don't need it to start again.  Only need it to start at zero and stop, and be reset to zero.

Now I can move on to the rest of the project.

Heres the code I have for the timer.

Thanks again.
Code:
int startSECOND, startMINUTE, startTOTAL;
int stopSECOND, stopMINUTE, stopTOTAL;
int dis_m, dis_s;
boolean startcount = false;
PFont font10;
PFont font24;

void setup()
{
 //setup fonts for use throughout the application
 font10 = loadFont("Verdana-10.vlw");
 font24 = loadFont("Verdana-24.vlw");

size(600,200);

}

void draw()
{

drawbuttons();
if(mousePressed && rectSTART())
{
startSECOND=second();
startMINUTE = minute();
startTOTAL = startMINUTE*60 + startSECOND;
startcount = true;
}

if(mousePressed && rectSTOP())
{
startcount = false;
}

if(mousePressed && rectRESET())
{
 
dis_m = 0;
dis_s = 0;

}

calculate();
display();
}

void drawbuttons()
{
fill(6,203,27);  rect(400,45,50,20); // green start
fill(250,0,17);  rect(400,70,50,20); // red stop
fill(250,122,30);  rect(400,95,50,20); //orange reset

fill(0);
   textFont(font10);  
   textAlign(CENTER);
   text("Start", 425,59);
   text("Stop", 425, 84);
   text("Reset", 425, 109);
}

boolean rectSTART()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 45 && mouseY <= 65) return true;
else return false;
}

boolean rectSTOP()
{
if(mouseX >= 400 &&  mouseX <= 450 && mouseY >= 70 && mouseY <= 90) return true;
else return false;
}

boolean rectRESET()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 95 && mouseY <= 115) return true;
else return false;
}

void calculate()
{
if(startcount)
{
stopMINUTE = minute();
stopSECOND = second();

stopTOTAL = stopMINUTE*60 + stopSECOND;

int diff = stopTOTAL-startTOTAL;
dis_m = diff/60;
dis_s = diff - dis_m*60;
}
}
void display()
{
stroke(0);
   fill(255,255,255);
 rect(460,50,100,60); // stopwatch  
fill(0);
textFont(font24);
textAlign(LEFT);
text(nf(dis_m,2)+":"+nf(dis_s,2),477,88);
}


Re: timer/stop watch mouse start and stop
Reply #18 - Aug 30th, 2009, 3:55pm
 
I've been using the code above, but as it turns out, it starts to count down from -59:-59 after random times..  

I'm assuming since I've tried to edit out the pause, restart function.  Basically I want the time to freeze when stopped and then when it resets, to start at 00:00.  As it stands right now, it works as planned.  It doesn't start until I hit start and it pauses time.  I just need to make it count seamlessly to at least 20:00, without going negative.
Re: timer/stopwatch mouse start/stop - calc. problem
Reply #19 - Sep 1st, 2009, 9:46am
 
i should converse with myself more often.

Finally figured it out.

Thanks all.

Pages: 1 2