// Arduino code to print "start" then delay 3 seconds with millis and after delay finish print "done" and the elapsed time. Clear serial monitor before print.
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
// clear the serial monitor by sending a special character:
Serial.write(12);
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(13, LOW);
// print "start" to the serial monitor:
Serial.println("start");
// get the current time in milliseconds:
unsigned long startTime = millis();
// wait for 3 seconds using millis():
while (millis() - startTime < 2000) {
// do nothing
}
// get the elapsed time in milliseconds:
unsigned long elapsedTime = millis() - startTime;
// print "done" and the elapsed time to the serial monitor:
Serial.print("done");
Serial.print(" in ");
Serial.print(elapsedTime);
Serial.println(" milliseconds");
}