uint16_t motorGeschwidigkeit =  1000; // max: 16000 je höher desto langsamer

void run(int8_t step)
{
  yield();

  static uint8_t phase;

  phase = (phase + step) & 7;    // Schritte addieren und Modulo 8 bilden

  switch (phase) 
  {
    case 0:    //Phase 1
      digitalWrite(PIN_IN4, HIGH);
      digitalWrite(PIN_IN3, LOW);
      digitalWrite(PIN_IN2, LOW);
      digitalWrite(PIN_IN1, LOW);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 1: //Phase 2
      digitalWrite(PIN_IN4, HIGH);
      digitalWrite(PIN_IN3, HIGH);
      digitalWrite(PIN_IN2, LOW);
      digitalWrite(PIN_IN1, LOW);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 2: //Phase 3
      digitalWrite(PIN_IN4, LOW);
      digitalWrite(PIN_IN3, HIGH);
      digitalWrite(PIN_IN2, LOW);
      digitalWrite(PIN_IN1, LOW);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 3: //Phase 4
      digitalWrite(PIN_IN4, LOW);
      digitalWrite(PIN_IN3, HIGH);
      digitalWrite(PIN_IN2, HIGH);
      digitalWrite(PIN_IN1, LOW);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 4: //Phase 5
      digitalWrite(PIN_IN4, LOW);
      digitalWrite(PIN_IN3, LOW);
      digitalWrite(PIN_IN2, HIGH);
      digitalWrite(PIN_IN1, LOW);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 5: //Phase 6
      digitalWrite(PIN_IN4, LOW);
      digitalWrite(PIN_IN3, LOW);
      digitalWrite(PIN_IN2, HIGH);
      digitalWrite(PIN_IN1, HIGH);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 6: //Phase 7
      digitalWrite(PIN_IN4, LOW);
      digitalWrite(PIN_IN3, LOW);
      digitalWrite(PIN_IN2, LOW);
      digitalWrite(PIN_IN1, HIGH);
      delayMicroseconds(motorGeschwidigkeit);
      break;

    case 7: //Phase 8
      digitalWrite(PIN_IN4, HIGH);
      digitalWrite(PIN_IN3, LOW);
      digitalWrite(PIN_IN2, LOW);
      digitalWrite(PIN_IN1, HIGH);
      delayMicroseconds(motorGeschwidigkeit);
      break;
  }
}

void stop()
{
  digitalWrite(PIN_IN4, LOW);
  digitalWrite(PIN_IN3, LOW);
  digitalWrite(PIN_IN2, LOW);
  digitalWrite(PIN_IN1, LOW);
}

void pin_konfig()
{
  pinMode(PIN_IN1, OUTPUT);
  pinMode(PIN_IN2, OUTPUT);
  pinMode(PIN_IN3, OUTPUT);
  pinMode(PIN_IN4, OUTPUT);
}
