unsigned long
  motorTmr = 0,
  processTmr= 0;
       
float
  processDelay = 630, // Общее вращение
  motorDelay = 1; // Для обмоток мотора

bool
    currentDirection = false,
    left_flag = 1,//false,
    right_flag = 1;//false;

const byte
  leftSensor = 8,
  rightSensor = 9,
  dirPin = 3,
  stepPin = 2;

void setup(){Serial.begin(115200);
  pinMode(leftSensor, INPUT);
  pinMode(rightSensor, INPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  motorTmr = processTmr = millis();
}

void loop(){

if(digitalRead(leftSensor)){
        processTmr = millis();Serial.println("left");
        currentDirection = true;
    }

    if(digitalRead(rightSensor)){
        processTmr = millis();Serial.println("right");
        currentDirection = false ;
    }



    if (millis() - processTmr <= processDelay){
        if(millis() - motorTmr >= motorDelay){
            motorTmr = millis();
            digitalWrite(dirPin, currentDirection);
            digitalWrite(stepPin, !digitalRead(stepPin));
        }  
    } else {
        processTmr = millis();
        currentDirection = !currentDirection;
    }
}