Inserting code in the forum as a code-section
I want to write some basic information. You should follow some rules to get better help.
If you want to post code this is the most comfortable way to do it:
make the Arduino-IDE the active window
point with the mouse-arrow somewhere into the code
do a rightclick on the mouse
and choose "copy for forum"
This will copy the whole code into the clipboard
This will add the code-tags right on top of the first line of code and right below the last line of code
make your browser the active window and paste clipboard
As a code-Section it shows up as a smaller window which is browsable on its own
and has a select-function which makes it possible to select the entire code by one mouseclick for other users.
To your code delayMicroseconds(2); does what its name says: delay for 0,000002 seconds.
So as a human beeing you won't recognize such a short "delay".
baldengineer.com has a very good tutorial about timing with function millis() too .
There is one paragraph that nails down the difference between function delay() and millis() down to the point:
The millis() function is one of the most powerful functions of the Arduino library. This function returns the number of milliseconds the current sketch has been running since the last reset. At first, you might be thinking, well that’s not every useful! But consider how you tell time during the day. Effectively, you look at how many minutes have elapsed since midnight. That’s the idea behind millis()!
Instead of “waiting a certain amount of time” like you do with delay(), you can use millis() to ask “how much time has passed”?
and this is the essence and the fundamental difference between blocking timing with delay() ;
and non-blocking timing with function millis();
baldengineers: millis() Tutorial: Arduino Multitasking
As a general introduction to programming Arduinos this website is very good
Arduino Programming Course
It is easy to understand and a good mixture between writing about important concepts
and get you going.
best regards Stefan