Arduino Tips And Hints

Arduino Tips And Hints

The analogWrite() function uses PWM, so if you want to change the PWM pin you’re using, be sure to use another PWM capable pin. On most Arduino, the PWM pins are identified with a “~” sign, like ~3, ~5, ~6, ~9, ~10 and ~11.


Adafruit has a complete library of sketches that use PIXEL leds.


The DFminiplayer is made by DF Robot . The spec sheet on the miniplayer is extremely helpful.


The function millis is just a number that represents milliseconds since the code started.  Delay halts your program until the requested interval has elapsed.

To delay without halting, do something like this.

unsigned long trgetTime=0

targetTime=millis()+10000 // how long you want to wait.

Then in the main loop:

if ( target tim > millis() )

{targetTime = 0 // or ext interval

// do timed action



You can use millis() ad delay in the same program without any trouble.

Us T1 = millis() at the start of the loop()

then at the end, T2 = millis() – T1

This gives the elapsed time for that cycle through the loop.

If you want to delay a certain amount extra:


or to always have the same amount of time per cycle:

delay(max(1, fixedTime-T2)); (can’t have negative delays.


Note that there is one special situation.  If the millis() counter has rolled-over during the cycke, then T2 becomes negative.  The “simplest” way around his is to change the T2 assignment to:

T2 = max(minT2, (millis() – T1));

where minT2 is he smallest amount of time that you expect the loop to require.


if (t2-t1 >=1000){

t1 os mever omotoa;oed befpre ots reference here.  So t2-t1 is undefined  as to what it will actually produce. There are rare circumstances where C++ will initialize certain variables, but this is not one of them.

Tell others about this information by using one of these services. Thank you for the support.
Scroll to top