 static volatile bool emergencyStopPressed = false;
 static volatile bool limitSwitchOpenActive = false;
 static volatile bool limitSwitchCloseActive = false;
+static volatile int encoderState = 0;
+static volatile int encoderPosition = 0;
 
 void setup() {
 

    pinMode(PIN_BUTTON_EMERGENCYSTOP, INPUT);
    pinMode(PIN_LIMITSWITCH_OPEN, INPUT);
    pinMode(PIN_LIMITSWITCH_CLOSE, INPUT);

    attachInterrupt(digitalPinToInterrupt(PIN_BUTTON_EMERGENCYSTOP), emergencyStopISR, CHANGE);
    attachInterrupt(digitalPinToInterrupt(PIN_LIMITSWITCH_CLOSE), limitSwitchCloseISR, CHANGE);
    attachInterrupt(digitalPinToInterrupt(PIN_LIMITSWITCH_OPEN), limitSwitchOpenISR, CHANGE);

    Serial.begin(57600);
    handler.registerCommand("TEST", test);

        if (roofState == CLOSING && phase == CLOSE_TIGHTLY) {
            roofState = CLOSED;
            phase = IDLE;
            encoderPosition = 0;
        } else {
            roofState = ERROR;
            phase = IDLE;
