The notion of time/duration is super important when you program, especially on embedded systems like Arduino. Writing a code that takes too much time, and not being able to know it, can lead to severe problems in your overall application.
For this post the goal will be to measure the duration of the famous digitalWrite() function. You’ll also get a template that you can use for measuring any piece of code you want in your Arduino programs.
Quick note before we get started: the duration you’ll measure will depend on your hardware. If you use an Arduino Uno or an Arduino Due (more computation power), you’ll get different results. For this tutorial I’ll be using an Arduino Uno.
End Of Post