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 <= 4000)
{
if (holdDuration >= 4000 && !print4)
{
Serial.println("tt_sound:2");
print4 = true;
}
else if (holdDuration >= 3000 && !print3)
{
Serial.println("tt_sound:1");
print3 = true;
}
else if (holdDuration >= 2000 && !print2)
{
Serial.println("tt_sound:1");
print2 = true;
}
else if (holdDuration >= 1000 && !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.