Sorry, but no digitalWrite and delay are used in an interrupt function in this code, here are the interrupts functions.
void countingballs(){
Time1 = millis();
if(Time1 - lastTime1 > 250){
count_d++;
lastTime1 = Time1;
}
}
void counting(){
count++;
}
void stateInv(){
y = 1;
}