         }
         case RAMP_DOWN: {
             int power = FULL_SPEED - FULL_SPEED * countSincePhase / RAMP_LENGTH;
-            if (power < 0)
-                power = 0;
+            int minimumPower = (roofState == CLOSING ? CLOSING_SPEED : 0);
+            if (power < minimumPower)
+                power = minimumPower;
             motorShield.setM1Speed(power * direction);
-            if (power == 0) {
+            if (power == minimumPower) {
                 phase = IDLE;
                 if (roofState == STOPPING)
                     roofState = STOPPED;
                 else if (roofState == OPENING)
                     roofState = OPEN;
                 else if (roofState == CLOSING)
-                    roofState = CLOSED;
+                    phase = CLOSE_TIGHTLY;
             }
             break;
         }
+        case CLOSE_TIGHTLY:
+            // just coast ahead, until we trigger current limit when the roof hits the wall
+            break;
     }
 }
 

    handler.registerCommand("CLOSE", close);
    handler.registerCommand("STOP", stop);

    taskScheduler.init();
    taskScheduler.addTask(motorTask);
    taskScheduler.addTask(buttonTask);

#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();
