/* 23/07/21 * delayMillisv4 * Using millis() to control 3 timers with different timings. */ int q; unsigned long timer1 = 0; unsigned long timer2 = 2000; unsigned long timer3 = 4000; void setup() { // Serial.begin(9600) starts serial communication. 9600bps bits per second = 1200 characters per second Serial.begin(9600); //Send script name Serial.println("delayMillisv4..."); //this will print a blank line Serial.println(" "); } void loop(){ if(millis() > timer1){ //take the current time and add 6 seconds (6000); timer1 = millis() + 6000; Serial.println("1st Item"); for(q=0;q<100;q++){ Serial.println(q); } } //if the value of millis is above the timer value if(millis() > timer2){ //take the current time and add 3.5 seconds (3500) to reset the timer timer2 = millis() + 3500; Serial.println("2nd Item"); } if(millis() > timer3){ //take the current time and add 2 to 8 seconds (2000 - 8000); timer3 = millis() + random(2000,8000);; Serial.println("3rd Item"); } }