unsigned int score = 0;
bool motors_down = false;
unsigned int start = 0,
motors_down_score = 0,
motors_down_time = 0;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0)); // start random generator
start = millis();
motors_down_time = start;
}
void loop() {
score=score+random(10); // increase score by a random number to simulate its increasing
Serial.print((millis()-start)/1000); // print time in sec.
Serial.print(" ");
Serial.print(score);
if (!motors_down && score/20 >= 1) { // '20' hard-coded > later put this into variable to do it for 30...40...
motors_down = true; // turn down the motors
motors_down_score = score;
motors_down_time = millis();
}
else if (motors_down && score > motors_down_score && (millis()-motors_down_time)/1000 > 30 ) { // 30 sec. past?
motors_down = false; // turn up the motors
motors_down_score = 0;
motors_down_time = 0;
}
Serial.print(" motors_down="); Serial.print(motors_down);
Serial.println("");
delay(random(10000)); // random delay of max. 10 sec
}