We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a timer using CP5 Library and I was wondering if there's a pause option to stop the time on screen. I'm using the following code.
// user interface Desktop
import controlP5.*;
ControlP5 cp5;
ControlTimer c;
Textlabel t;
boolean Startbutton = false;
void setup(){
size(500,500);
noStroke();
cp5 = new ControlP5(this);
//Timer
frameRate(30);
cp5 = new ControlP5(this);
c = new ControlTimer();
t = new Textlabel(cp5,"--",100,100);
c.setSpeedOfTime(60);
// create a new button with name 'buttonA'
cp5.addButton("Stop")
.setValue(0)
.setPosition(100,100)
.setSize(40,20)
;
}
void draw(){
background(0);
if (Startbutton){
cp5.addButton("Stop")
.setValue(0)
.setPosition(100,100)
.setSize(40,20)
;
t.setValue(c.toString());
t.draw(this);
t.setPosition(100, 120);
}
else{
cp5.addButton("Start")
.setValue(0)
.setPosition(100,100)
.setSize(40,20)
;
c.reset();
}
}
void mousePressed() {
if (mouseX > 100 && mouseX < 140 && mouseY > 100 && mouseY < 120) {
Startbutton = !Startbutton;
}
}
Answers
There is no pause button in the ControlTimer class, according to the ControlP5 reference: http://www.sojamo.com/libraries/controlP5/reference/controlP5/ControlTimer.html
You'd have to improvise using 2 timers. 1 will constantly keep going (until you stop it, entirely), whereas the other one is started when you press the "Pause" button. You'd also have to keep track of the previous pause durations, and add them to a variable, to allow for multiple pausing.
Otherwise, I don't think there's another way.
I'll try to provide an example when I get back.
-- MenteCode