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);
}