skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home Products Teensy Blog Forum
You are here: Teensy Teensyduino Timing Delay

PJRC Store
Teensy 3.6, $29.25
Teensy 3.5, $24.25
Teensy 3.2, $19.80
Teensy LC, $11.65
Teensy 2.0, $16.00
Teensy++ 2.0, $24.00
Teensy
Main Page
Hardware
Getting Started
How-To Tips
Code Library
Projects
Teensyduino
Reference

Simple Delay

Why use complex timing functions if simple ones will work? These simple Arduino delay functions just wait a fixed amount of time.

delay()

The simplest timing function is delay(). It waits a number of milliseconds.

digitalWrite(11, HIGH);  // pin 11 high
delay(1000);             // for 1 second
digitalWrite(11, LOW);  

For very precise delays, you can use delayMicroseconds(), up to 16383 us. With delay(), you can wait up to 429497295 ms, or about 49.7 days.

While these functions are easy, your program can not do other work during the delay.

delayMicroseconds()

generally use for short, hardware motivated delays

TODO: example with mux to adc

interrupts can change delay, must disable interrupts if timing is critical

Very short delays, less than 1 microsecond, can be achieved by NOP instructions. Careful testing is needed to get accurate results.