#include <MobaTools.h>
// Stepper connections - Please adapt to your own needs.
const byte dirPin    = 2;
const byte stepPin   = 3;

const byte buttonPin[] = {7} ; 
const byte buttonCnt = sizeof(buttonPin);                  // number of buttons/positions

const int debounceTime =   20; // 20 milliseconds
const int pressingTime = 1000; // 1000 milliseconds

MoToButtons myButton( buttonPin, buttonCnt, debounceTime, pressingTime );

const int stepsPerRev = 200;    // Steps per revolution - may need to be adjusted

long upStepPosition   = 10000;
long downStepPosition =    0;

MoToStepper stepper1( stepsPerRev, STEPDIR );  // create a stepper instance

boolean IsInPositionUp = true;


void setup() {
  Serial.begin(115200);
  Serial.println("Setup-Start");
  stepper1.attach( stepPin, dirPin );
  stepper1.setSpeed( 2500 );             
  stepper1.setRampLen( stepsPerRev / 2); // Ramp length is 1/2 revolution
}

void loop() {
  myButton.processButtons();  // Check buttonstate

  if ( myButton.pressed(0) ) {  // button numbering starts at zero. 1 button check button number 0
    // if pressing down is detected
    Serial.println();
    Serial.println("pressing down detected");
    if (IsInPositionUp == true) {
      moveToDownPosition(); // excecute lines defined in "void "downPosition()"
    }
    else {
      moveToUpPosition();    // excecute lines defined in "void "upPosition()"
    }
  }
}




void moveToUpPosition() {
  Serial.println("entering function upPosition");
  Serial.print("move motor to position ");
  Serial.println(upStepPosition);
  
  stepper1.moveTo(upStepPosition);
  IsInPositionUp = true;
  Serial.println("exiting function upPosition");
} // end of definition of function "upPosition()"


void moveToDownPosition() {
  Serial.println("entering function downPosition");
  stepper1.moveTo(downStepPosition);
  Serial.print("move motor to position ");
  Serial.println(downStepPosition);
  IsInPositionUp = false;  // which means is in position down
  Serial.println("exiting function downPosition");
} // end of definition of function "downPosition()"
A4988