How to tigger a timer using a button...
in
Programming Questions
•
2 years ago
I am trying to trigger a timer that counts down from 10 infinitely once a button is pressed. The button should grow once pressed. I have been able to get the button and the timer to work independently, but have not been able to delay the timer start until the button is pressed. Below is the code. Any suggestions?
int x = 300;
int y = 600;
int r = 40;
int grow = 0;
PFont font;
void setup() {
background(204);
size(600,600);
ellipseMode(RADIUS);
smooth();
font = loadFont ("ArialMT-22.vlw");
textFont (font);
}
void draw() {
background(204);
float d = dist(mouseX, mouseY, x, y);
int timer;
timer = (((millis())/1000)*-1)+10;
println(timer);
r= r+ grow;
if((mousePressed) && (d < r) && (r<=40)) {
grow = 1;
}
textSize(16);
fill(255);
ellipse(x, y, r, r);
fill(0);
text("COUNT", 275, 595);
fill(0);
text(timer, 300, 40);
}
int x = 300;
int y = 600;
int r = 40;
int grow = 0;
PFont font;
void setup() {
background(204);
size(600,600);
ellipseMode(RADIUS);
smooth();
font = loadFont ("ArialMT-22.vlw");
textFont (font);
}
void draw() {
background(204);
float d = dist(mouseX, mouseY, x, y);
int timer;
timer = (((millis())/1000)*-1)+10;
println(timer);
r= r+ grow;
if((mousePressed) && (d < r) && (r<=40)) {
grow = 1;
}
textSize(16);
fill(255);
ellipse(x, y, r, r);
fill(0);
text("COUNT", 275, 595);
fill(0);
text(timer, 300, 40);
}
1