PROGRAMMING: DELAYS
Compared with the computers we use every day, the Arno’s processor is very slow. But it can still do things much faster than we can see or react to. Most Arduinos are setup so they execute 16 million operations per second. We often need to slow things down so that we can actually see an LED blinking or have time to press a button. The delay statement tells the Arno to wait a certain number of milliseconds (1/1000th of a second):
// wait 500 milliseconds or ½ second
delay(500);
//wait 300 milliseconds, a blink of an eye!
delay(300);
//wait a whole 10 seconds!
delay(10000);
Sometimes a millisecond is just too long to wait. We can also wait a few microseconds (1 millionth of a second!).
delayMicroseconds(10);
Another useful command is millis() which gives us the number of milliseconds since the sketch started:
long howLong = millis();
You can use this command to measure how much time has passed since something last happened, such as a button being pressed. If you need to count microseconds you can use micros() to count the number of microseconds since the sketch began.
// wait 500 milliseconds or ½ second
delay(500);
//wait 300 milliseconds, a blink of an eye!
delay(300);
//wait a whole 10 seconds!
delay(10000);
Sometimes a millisecond is just too long to wait. We can also wait a few microseconds (1 millionth of a second!).
delayMicroseconds(10);
Another useful command is millis() which gives us the number of milliseconds since the sketch started:
long howLong = millis();
You can use this command to measure how much time has passed since something last happened, such as a button being pressed. If you need to count microseconds you can use micros() to count the number of microseconds since the sketch began.