Code help for automatic convertible top

I got this code from someone and it is supposed to open and close a convertible top without holding the switch in the open or close positions

At first, it would pulse the output so the top moved in steps. I removed the delay(50) command and it now is smooth operation, however it does not keep the output HIGH, it is only HIGH as long as the switch is closed. Basically just like the switch normally does, not adding any functionality

In the code it defines openTime and closeTime in ms, but I don’t see anywhere that those are used and they define how long the respective output is HIGH

The control switch in the car is momentary. The end result is that a short press on either open or close (<250ms) will result in the top moving for the time set in openTime or closeTime respectively. If you hold the switch for > 250ms it will operate in manual mode i.e. move as long as you hold the switch. The other thing that is very important is that if in auto mode any press of either switch must stop movement immediately.

I am very new to programming and sure could use some help in getting this to work. I have been trying to figure it out using example code, but so far no luck. Other than getting it to not pulse I have with the delay command get pin 2 or 3 to stay HIGH, but that won’t work as I must be able to with another button press change both to LOW immediate (stop the top from moving)

I am thinking that the code I received is missing something.

I am using a NANO if that makes a difference

Thanks in advance
Jay

/*
  986 Auto-Top by Alex Roy
  This auto-presses the open or close buttons for the convertible top on a Porsche 986
  for the specified open/close seconds automatically if you quickly tap the button.
  If the button tap is longer (eg it is held down), the button is only autp-pressed 
  for the same amount of time as the user is pressing.
  
  If the top is already automatically opening or closing, a second press of either 
  button cancels the auto-open proceedure.
  
  My 2001 Boxster S open/close timing:
  13.6sec to open
  14.4sec to close
 */
 
 #define openBtnOut     2
 #define closeBtnOut    3
 #define openBtnIn      7
 #define closeBtnIn     8
 
 int movementCount = 0;
 int openBtnCount = 0;
 int closeBtnCount = 0;
 int openMode = 0; //0=no auto movement, 1=auto open, 2 = auto close, 3 = manual open, 4 = manual close
 #define shortPressInterval 250
 #define loopInterval 50
 
 #define openTime 15600;
 #define closeTime 16400;
 
 void setup() {
   pinMode(openBtnOut, OUTPUT);
   pinMode(closeBtnOut, OUTPUT);
   
   pinMode(openBtnIn, INPUT);
   pinMode(closeBtnIn, INPUT);
   
   allStop();
 }
 
 void loop() {
   //check buttons
   if(digitalRead(openBtnIn) == HIGH) {
     if(openBtnCount < 32000) {
       openBtnCount += loopInterval;
     }
     closeBtnCount = 0;
     digitalWrite(closeBtnOut, LOW);
      digitalWrite(openBtnOut, HIGH);
   } else {
     openBtnCount = 0;
     digitalWrite(openBtnOut, LOW);
   }
   
   if(digitalRead(closeBtnIn) == HIGH) {
     if(closeBtnCount < 32000) {
       closeBtnCount += loopInterval;
     }
     openBtnCount = 0;
     digitalWrite(openBtnOut, LOW);
     digitalWrite(closeBtnOut, HIGH);
   } else {
     closeBtnCount = 0;
     digitalWrite(closeBtnOut, LOW);
   }
   
   switch(openMode) { ////0=no auto movement, 1=auto open, 2 = auto close, 3 = manual open, 4 = manual close
     case 1: //currently auto-opening
       movementCount -= loopInterval;
       if(openBtnCount > shortPressInterval) { //if the interval is greater, transition to manual open mode
         openMode = 3;
       } else { //continue with auto-open
         if(movementCount <= 0 || closeBtnCount > 0) { //stop auto-open function
           allStop();
         } else { //continue with auto-open function
           //continue with current pin state
         }
       }
       break;
       
     case 2: //currently auto-closing
       movementCount -= loopInterval;
       if(closeBtnCount > shortPressInterval) { //if the interval is greater, transition to manual close mode
         openMode = 4;
       } else { //continue with auto-close
         if(movementCount <= 0 || openBtnCount > 0) { //stop auto-open function
           allStop();
         } else { //continue with auto-close function
           //continue with current pin state
         }
       }
       break;
       
     case 3: //currently manually opening
       movementCount -= loopInterval;
       if(openBtnCount > 0) {
         //continue with current pin state
       } else {
         allStop();
       }
       break;
       
     case 4: //currently manually closing
       movementCount -= loopInterval;
       if(closeBtnCount > 0) {
         //continue with current pin state
       } else {
         allStop();
       }
       break;
       
     default: //no movement currently
       movementCount -= loopInterval;
       if(openBtnCount > 0) {
         openMode = 1;
         digitalWrite(closeBtnOut, LOW);
         digitalWrite(openBtnOut, HIGH);
       } else if(closeBtnCount > 0) {
         openMode = 2;
         digitalWrite(closeBtnOut, HIGH);
         digitalWrite(openBtnOut, LOW);
       } else {
         allStop();
       }
       
       break;
   }
   
   // delay(50);
 }
 
 void allStop() {
   digitalWrite(openBtnOut, LOW);
   digitalWrite(closeBtnOut, LOW);
   openMode = 0;
   movementCount = 0;
   openBtnCount = 0;
   closeBtnCount = 0;
 }

It doesn't seem to be a complex requirement so it may be quicker to write your own code rather than try to figure out some other person's.

What happens (in manual mode) if you hold your finger on the button after the roof is fully open or closed - has the car got an automatic cut-out to prevent overloads? It doesn't look like the Arduino would know if it had gone too far. I'd hate to ruin a Boxster. The repairs would pay for a few Arduinos !

...R

there is an auto cut-off so you won't damage the roof