   14.4sec to close
 */
 
+
+// pin definitions
 #define openBtnOut     2
 #define closeBtnOut    3
 #define pBrakeOut      4
 #define openBtnIn      8
 #define closeBtnIn     9
 
+// cutoff point, after which a press is considered a long press
 #define shortPressInterval 250
+// loop delay
 #define loopInterval 50
 
+// time taken to open top
 #define openTime 15600
+// time taken to close top
 #define closeTime 16400
 
+// operation modes
 #define modeNull 0
 #define modeAutoOpen 1
 #define modeAutoClose 2
 #define modeManualOpen 3
 #define modeManualClose 4
 
+int closeBtnCount = 0;
+int openBtnCount = 0;
 int movementCount = 0;
-int openBtnCount = 0;
-int closeBtnCount = 0;
+
 int openMode = modeNull;
 bool btnReleased = false;
 bool ignoreBtn = false;

}

void checkButtons() {

  //check buttons
  if(digitalRead(openBtnIn) == HIGH) {
    if(btnReleased){
      allStop();
      ignoreBtn = true;
    } else if(ignoreBtn == false) {
      if(openBtnCount < 32000) {
        openBtnCount += loopInterval;
      }
      closeBtnCount = 0;
      digitalWrite(closeBtnOut, LOW);
    }
  } else if(digitalRead(closeBtnIn) == HIGH) {
    if(btnReleased){
      allStop();
      ignoreBtn = true;
    } else if(ignoreBtn == false) {
      if(closeBtnCount < 32000) {
        closeBtnCount += loopInterval;
      }
      openBtnCount = 0;
      digitalWrite(openBtnOut, LOW);
    }
  } else if (openMode != modeAutoOpen && openMode != modeAutoClose) {
    allStop();
    ignoreBtn = false;
  } else {


    default: //no movement currently
      if(openBtnCount > 0) {
        startAutoOpen();
      } else if(closeBtnCount > 0) {
        startAutoClose();
      } else {
        allStop();
      }
      break;
  }
}

void startAutoOpen() {
  openMode = modeManualOpen;
  movementCount = openTime;
  digitalWrite(pBrakeOut, HIGH);
  digitalWrite(closeBtnOut, LOW);
  digitalWrite(openBtnOut, HIGH);
}

void startAutoClose() {
  openMode = modeManualClose;
  movementCount = closeTime;
  digitalWrite(pBrakeOut, HIGH);
  digitalWrite(openBtnOut, LOW);
  digitalWrite(closeBtnOut, HIGH);
}

void allStop() {
