You need to use some flags.
So take this part out
digitalWrite(4, HIGH); // set the Mosfet On
digitalWrite(6, HIGH); // set the LED on
delay(5000); // wait for 5 seconds
digitalWrite(4, LOW); // set the Mosfet Off
digitalWrite(6, LOW); // set the LED Off
put in
startTime = millis();
startFlag = 1;
then add some other if statement after the else{}:
if (startFlag ==1 & ( millis() - startTime < duration){
do the high writes;
}
if (startFlag ==1 & ( millis() - startTime >=duration){
clear the flag:
startFlag = 0;
}
and in this else
else if (value == 7419139)
clear the flag
startFlag = 0;
and add 1 more check:
if (startFlag == 0){
do the low writes
}
startTime & duration are unsigned long variable types (32 bit numbers)