Countdown timer to change state / mode
in
Programming Questions
•
5 months ago
I've managed to configure my program to respond to keyPressed and mousePressed with the result to change the mode.
I'm now trying to get a timer to start counting down at mode==2 and when the timer finishes {mode=3}. I know that this part works
- class DownTimer {
- //***local variables
- int startTime;
- float countDown;
- // ***constructor
- DownTimer(){
- countDown=4000;
- }
- //***functions
- void start(){
- startTime=millis();
- }
- boolean timeEnd() {
- int timeGone=millis()- startTime;
- if (timeGone>countDown) {return true;}
- else {return false;}
- }
- }
- void downTimer(){
- downTimer=new DownTimer();
- if (mode==2) {downTimer.start();}
- if(downTimer.timeEnd())
- {mode=3;
- downTimer.start();}
- }
1