How to avoid the code interrupting itself?
You can't use threads on an arduino, they don't exist. you can get some pseudo multitasking going with interrupts, but that is not necessary in your case.

You should be able to refactor your code to avoid using delays without much work. The arduino library provides millis() to keep tract of the time since the arduino was powered on in milliseconds.

something like this could replace all the delays in your code

static boolean state;
static uint32_t time;
if(time &lt; millis()){
    time += delayFromPercent(percentValue);

    state = !state;
    if(percentage &lt; 1.0) state = false;
    digitalWrite(in1, state);
}


Then, somewhere else place

uint32_t delayFromPercent(float percent){
    if(percent &lt; 25) return 100;
    if(percent &lt; 50) return 50;
    if(percent &lt; 75) return 25;
    return 10;
}


alternately, if you don't really want the discrete steps, you could use this instead

uint32_t delayFromPercent(float percent){
    return max(10, 100-percent); // don't return less than 10ms
}


you could change it to react a bit quicker by comparing the time plus calculated delay now rather than when it last set the pin, but that strays farther from what your initial implementation would have done. 

In any case, this code will should be able to switch pin in1 without making the rest of your code slow down, as long as the other code does not use delays either.