Arduino Leonardo timing Inconsistency I've got a question regarding the use of Millis() on a Leonardo Arduino. I'm currently using it to time 4 seconds elapsed while sending a serial message every second. These messages play a sound. On the fourth message the sound is different to signify that the Arduino has started an event. 

I'm running into an issue where the sounds are occasionally being played sporadically without a consistent 1 second between them. I'm wondering if there is a better way of doing what I'm doing? During the timing the Arduino is doing nothing else, and the receiving computer is also generally not doing anything taxing. Is this even an issue from the Arduino side? My receiving program is written in C# using System.IO.Ports.SerialPort. 

The reason this is done through Arduino is because the event started by the Arduino needs to correspond exactly to the sounds, though if this remains unresolved I will need to rework this.   

Edit: Code as requested.

void setup()
{
    //Setup Code
}

void loop()
{
    //Code that handles other serial messages and various states
    if (isSpecificState == true)
        onSpecificState();
}

void onSpecificState()
{
    //Setup to handle state

    long holdStart = millis();
    long holdDuration = 0;

    boolean print1 = false;
    boolean print2 = false;
    boolean print3 = false;
    boolean print4 = false;

    while(holdDuration &lt;= 4000)
    {               
        if (holdDuration &gt;= 4000 &amp;&amp; !print4)
        {
            Serial.println("tt_sound:2");
            print4 = true;
        }            
        else if (holdDuration &gt;= 3000 &amp;&amp; !print3)
        {
            Serial.println("tt_sound:1");
            print3 = true;
        }
        else if (holdDuration &gt;= 2000 &amp;&amp; !print2)
        {
            Serial.println("tt_sound:1");
            print2 = true;
        }
        else if (holdDuration &gt;= 1000 &amp;&amp; !print1)
        {
            Serial.println("tt_sound:1");
            print1 = true;
        }
        holdDuration = millis() - holdStart;
    }

    //Handle state
}


As I mentioned in the comments, the Arduino is doing nothing else while the timing is happening.
There is only a very slight chance that you meet the holdDuration &gt;= 4000 condition in the while loop. Only when holdDuration will be exactly 4000 the while loop will be executed AND the subsequent test in the if statement will pass.

The serial print commands can easily take long enough to have millis() jump from a number less than 4000 to a number higher than 4000 in a single pass of the while loop.

To prove this assumption, increase the while test to holdDuration &lt;= 4100 and see if the intermittent effect goes away.