Alternative to delay function
// You don't need to return anything since it's just a delay
// also I changed the parameters to long ints because millis()
// returns a long int
void timeLoop (long int startMillis, long int interval){ // the delay function

    // this loops until 2 milliseconds has passed since the function began
    while(millis() - startMillis &lt; interval){} 
}

// Your call for a 2 millisecond delay would be
timeLoop(millis(), 2);


Also the leds may be acting weird because this schematic is wrong. As you can see one of the led's anode isn't connected to ground. It's circled in red.


If you really want it to return something you could use this:

long int timeLoop (long int startMillis, long int interval){ // the delay function

    while(millis() - startMillis &lt; interval){} 
    return millis() - startMillis;
}


But it really isn't needed.