     if (countSincePhase % 10 == 0) {
         status("");
         powerConsumptionLog.report(serial);
+    }
+
+    if (powerConsumptionLog.isOverload()) {
+        motorShield.setM1Speed(0);
+        if (roofState == CLOSING && phase == CLOSE_TIGHTLY) {
+            roofState = CLOSED;
+            phase = IDLE;
+        } else {
+            roofState = ERROR;
+            phase = IDLE;
+        }
     }
 
     if (emergencyStopPressed) {

        }
        case RAMP_DOWN: {
            int power = FULL_SPEED - FULL_SPEED * countSincePhase / RAMP_LENGTH;
            if (power < 0)
                power = 0;
            motorShield.setM1Speed(power * direction);
            if (power == 0) {
                phase = IDLE;
                if (roofState == STOPPING)
                    roofState = STOPPED;
                else if (roofState == OPENING)
                    roofState = OPEN;
                else if (roofState == CLOSING)
                    roofState = CLOSED;
            }
            break;
        }
    }
}


#define PIN_BUTTON_EMERGENCYSTOP 3
#define PIN_LIMITSWITCH_OPEN 18
#define PIN_LIMITSWITCH_CLOSE 19
#define MOTOR_CURRENT_LIMIT_MILLIAMPS 2500
#define MOTOR_POLARITY 1    // Change to -1 to invert movement direction
#define FULL_SPEED 400
#define CLOSING_SPEED 50
#define RAMP_LENGTH 20      // two seconds

void motorTick();
