We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi,
i am trying to make a nested timer in which the second timer starts after the first reaches its goal. then the first time starts again after the second reaches it goal. however, i can't seem to reset the second timer in the right condition statement. also, if i set a condition based on the timers reaching their limits, i only need a new limit to be generated once, but the time may not be exact, so setting an equality condition may yield no new limits because the time may not be exact. and if i set the condition in >, i get many new generations of a new limit.
thanks in advance, destro.
here is my code:
int testTime;
int nextTime;
int savedTime;
int savedNextTime;
int limit = 5000;
int newLimit;
void setup() {
size(200, 200);
savedTime = millis();
}
void draw() {
testTime = millis() - savedTime;
if(testTime < limit) println("testTime: " + testTime + ", " + "nextTime: " + nextTime);
// else if(testTime == limit) {
// newLimit = (int)random(5000, 11000);
// println("newLimit: " + newLimit);
// }
else if(testTime >= limit) {
newLimit = (int)random(5000, 11000);
println("newLimit: " + newLimit);
nextTime = millis() - savedNextTime;
if(nextTime < newLimit) println("nextTime: " + nextTime);
else if(nextTime >= newLimit) {
limit = newLimit;
savedTime = millis();
savedNextTime = millis();
}
}
}
Comments
Rather than nested you seem to want a linear arrangement where a timer triggers the start of a new timer when its limit is reached.
To prevent multiple timer restarts one solution would be to have a boolean that indicates when the limit has been reached. This boolean would initially (int setup) be set to false.
This sketch demonstrates what I mean
Sample output from this sketch
hi gotoloop and quark,
thanks for your suggestions. here is the sample code: