Serial not printing stepper steps while using IR remote

I'm having an issue with a WHILE loop statement. I'm trying to print the stepper steps while the stepper is moving. When I hold a button down on the IR remote, the stepper moves correctly then stops when I release the button but it doesn't print the position as it moves. I believe I have something wrong in the WHILE statement where it doesn't look at the timers correctly.

Here is the problem area -

// IR remote button controls-----------------------------------------------------------------------------------------------
void processButton()                   
{
  switch (results.value)
  {
    //**********************
    case 0xFF20DF:                                           // Buffer tank CW jog
      {
        Serial.println("Buffer tank CW jog");
        
        stepper_1.setSpeedSteps( 5000, 500 );
        stepper_1.moveTo(20000);
        TimerUp = millis();
        while (stepper_1.moving()) {
          TimerPtr = &TimerUp;  //point to this timer
          TimerUpFlag = true;   //enable timing
          if (TimerUpFlag && millis() - TimerUp >= 250ul)
  
          TimerUpFlag = false; //disable timing
          TimerPtr = &dummy;   //pointer to dummy timer
          stepper_1.stop();
          Serial.println(stepper_1.readSteps());
                
      }
      break;

Here is my complete code -



// changed to home against hard stop, no limit switch, 2 steppers. IR remote


#define MAX8BUTTONS // saves RAM because only 4 switches are used
#define MAX_STEPPER 6
#include <MobaTools.h>
#include "IRremote.h"


const int STEPS_PER_REV = 800;
const int POS_MAX = 20000;

// 40 meter positions---------------------------------------------------------------------------------------
const int BUFFER_TANK_FORTY_METER_POSITION = 5000;                        // Buffer tank
const int IPA_TANK_FORTY_METER_POSITION = 3500;                           // IPA tank
// 80 meter positions----------------------------------------------------------------------------------------
const int BUFFER_TANK_EIGHTY_METER_POSITION = 10000;                      // Buffer tank
// 160 meter positions------------------------------------------------------------------------------------------
const int BUFFER_TANK_ONESIXTY_METER_POSITION = 16000;                    // Buffer tank

//create stepper object ( 800 steps / rev - 1/4 microstep )---------------------------------------------------------

// Stepper 1 buffer tank
const byte stepper1_pul = 2;
const byte stepper1_dir = 3;
MoToStepper stepper_1( STEPS_PER_REV, STEPDIR );

// Stepper 2 IPA tank
const byte stepper2_pul = 4;
const byte stepper2_dir = 5;
MoToStepper stepper_2( STEPS_PER_REV, STEPDIR );

const byte enaPin = 7;



// create names for the buttons--------------------------------------------------------------------------------------------
// buttons must switch to Gnd
enum { buttonZero, buttonCW, buttonCCW, forty_meter_button, eighty_meter_button, onesixty_meter_button } ; 
const byte buttonPins[] = {22, 23, 24, 26, 27, 28 }; // assign pins to the buttons
const byte buttonCnt = sizeof(buttonPins);
MoToButtons myButton( buttonPins, buttonCnt, 20, 500 );


// IR remote --------------------------------------------------------------------------------------------------
const byte RECV_PIN = 8;   //IR receive pin                                  
 
IRrecv irrecv(RECV_PIN);   //create instance of 'IRrecv'
decode_results results;    //create instance of 'decode_results'
 
unsigned long   TimerUp;   //UP arrow on the remote
boolean         TimerUpFlag = false;
 
unsigned long   TimerDown; //DOWN arrow on the remote
boolean         TimerDownFlag = false;

unsigned long   dummy;
unsigned long * TimerPtr = &dummy; //pointer to the current timer

const byte leftLED      = 10;  //toggles on/off
const byte rightLED     = 11;  //toggles on/off

 
 




// Setup--------------------------------------------------------------------------------------------------
void setup() { 
  Serial.begin(115200); while (!Serial);

// Stepper 1
  stepper_1.attach( stepper1_pul, stepper1_dir );
  stepper_1.attachEnable( enaPin, 10, LOW );                              // Enable active

// Stepper 2
  stepper_2.attach( stepper2_pul, stepper2_dir );
  stepper_2.attachEnable( enaPin, 10, LOW );                              // Enable active

  pinMode(LED_BUILTIN, OUTPUT);
 
  Serial.println("Starting loop");

  irrecv.enableIRIn();                                                    //IR remote start receive                

} 



// reading and processing the buttons ( debouncing and state change detection)------------------------------------------
void loop() 

{
  myButton.processButtons();          

  
    // check buttons and react accordingly
  if ( myButton.pressed(buttonZero) ) {                                   // home all steppers to zero position
    Serial.println(" Find ref point");
    toRefPoint();
  }
  if ( myButton.pressed(buttonCW) ) {                                     // jog slow clockwise direction
    Serial.println("Jog CW towards end");
    toCWdirection();
  }
  if ( myButton.pressed(buttonCCW) ) {                                    // jog slow counter clockwise direction
    Serial.println("Jog CCW back to 0 ");
    toCCWdirection();
  }
  if ( myButton.pressed(forty_meter_button) ) {                           // move to 40m position
    Serial.println("Move towards the 40M position");
    toFortyPoint();
  }
   if ( myButton.pressed(eighty_meter_button) ) {                         // move to 80m position
    Serial.println("Move towards the 80M position");
    toEightyPoint();
  }
   if ( myButton.pressed(onesixty_meter_button) ) {                       // move to 160m position
   Serial.println("Move towards the 160M position");
   toOnesixtyPoint();
  }
   
  if ( myButton.released(buttonCW) || myButton.released(buttonCCW) ) {
   Serial.println("Stop the stepper");
   stepper_1.rotate(0);
  }



  // IR remote controls------------------------------------------------------------------------------------------
  if (irrecv.decode(&results)) //is there IR remote button code
  {
    //Serial.println(results.value);
    processButton(); //process button press
    irrecv.resume(); //restart for next button press
  }
 

  // Jogging stop timers---------------------------
  //**********************                                // CW button release
  //if timing is enabled, is it time to stop
  if (TimerUpFlag && millis() - TimerUp >= 250ul)
  {
    TimerUpFlag = false; //disable timing
    TimerPtr = &dummy;   //pointer to dummy timer
    stepper_1.stop();
    stepper_2.stop();
    
  }
 
  //**********************                                // CCW button release
  //if timing is enabled, is it time to stop
  if (TimerDownFlag && millis() - TimerDown >= 250ul)
  {
    TimerDownFlag = false; //disable timing
    TimerPtr = &dummy;     //pointer to dummy timer
    stepper_1.stop();
    stepper_2.stop();
  }

}




// Homing: move all steppers to ref point and set zeropoint----------------------------------------------------------------------------
void toRefPoint() {                                    

    Serial.println("homing buffer tank...");                      // buffer tank start homing...
    stepper_1.setSpeedSteps( 20000, 200 ); 
    stepper_1.doSteps(-18000);
    while (stepper_1.moving()) {
      Serial.println(stepper_1.readSteps());
    }
    delay (1000);    
    Serial.println("hard stop reached, now move forward a small bit");
    stepper_1.doSteps(100);
    while (stepper_1.moving()) {
      Serial.println(stepper_1.readSteps());
    }
    Serial.println("now set zero");  
    stepper_1.setZero();
    stepper_1.moveTo(0);
    while (stepper_1.moving()) {
      Serial.println(stepper_1.readSteps());
    }
    Serial.println("buffer tank homing finished!");
    delay(1000);


      
    Serial.println("homing IPA tank...");                                  // IPA tank start homing...
    stepper_2.setSpeedSteps( 20000, 200 ); 
    stepper_2.doSteps(-2000);
    while (stepper_2.moving()) {
      Serial.println(stepper_2.readSteps());
    }
    delay (1000);    
    Serial.println("hard stop reached, now move forward a small bit");
    stepper_2.doSteps(100);
    while (stepper_2.moving()) {
      Serial.println(stepper_2.readSteps());
    }
    Serial.println("now set zero");  
    stepper_2.setZero();
    stepper_2.moveTo(0);
    while (stepper_2.moving()) {
      Serial.println(stepper_2.readSteps());
    }
    Serial.println("buffer tank homing finished!");
} 
  

// 40 meter position-------------------------------------------------------------------------------------------------
void toFortyPoint() {
  {                                                    // buffer tank 40 meter position
    stepper_1.setSpeedSteps( 40000, 500 );
    stepper_1.moveTo( BUFFER_TANK_FORTY_METER_POSITION ); 
    while (stepper_1.moving())
      Serial.println(stepper_1.readSteps());                              
  
  }
  delay (1000);
  {                                                    // IPA tank 40 meter position
    stepper_2.setSpeedSteps( 40000, 500 );
    stepper_2.moveTo( IPA_TANK_FORTY_METER_POSITION ); 
    while (stepper_2.moving())
      Serial.println(stepper_2.readSteps());                              
  
  }
}

// 80 meter position------------------------------------------------------------------------------------------------------
void toEightyPoint() {                                 // buffer tank 80 meter position
    stepper_1.setSpeedSteps( 40000, 500 );
    stepper_1.moveTo( BUFFER_TANK_EIGHTY_METER_POSITION ); 
    while (stepper_1.moving())
      Serial.println(stepper_1.readSteps());                              
  
  }

// 160 meter position-------------------------------------------------------------------------------------------------------
void toOnesixtyPoint() {                               // buffer tank 160 meter position
    stepper_1.setSpeedSteps( 40000, 500 );
    stepper_1.moveTo( BUFFER_TANK_ONESIXTY_METER_POSITION );
    while (stepper_1.moving())
      Serial.println(stepper_1.readSteps());                               
  
  }


// CW jog buttons-------------------------------------------------------------------------------------------------------------
void toCWdirection() {                                // buffer tank jog CW
  stepper_1.setSpeedSteps( 5000, 500 );
  stepper_1.moveTo(20000);

  while (stepper_1.moving() ) { // <<<= opening curly brace
    // reading in the state of the button again and again and again
    // how should your code "know" if a button is pressed or released LATER
    // The only way is to read-in the button-state
    // again and again and again I_N_S_I_D_E the while-loop
    myButton.processButtons(); // <<< read-in button-states

    if (myButton.released(buttonCW)) {
      stepper_1.stop();
      break;
    }
    Serial.println(stepper_1.readSteps());
  }
}     
                                       
  
// CCW jog buttons------------------------------------------------------------------------------------------------------------
void toCCWdirection() {                                // buffer tank jog CCW
  stepper_1.setSpeedSteps( 5000, 500 );
  stepper_1.moveTo(0);

  while (stepper_1.moving() ) { // <<<= opening curly brace
    // reading in the state of the button again and again and again
    // how should your code "know" if a button is pressed or released LATER
    // The only way is to read-in the button-state
    // again and again and again I_N_S_I_D_E the while-loop
    myButton.processButtons(); // <<< read-in button-states

    if (myButton.released(buttonCCW)) {
      stepper_1.stop();
      break;
    }
    Serial.println(stepper_1.readSteps());
  }
}   
 

// IR remote button controls-----------------------------------------------------------------------------------------------
void processButton()                   
{
  switch (results.value)
  {
    //**********************
    case 0xFF20DF:                                           // Buffer tank CW jog
      {
        Serial.println("Buffer tank CW jog");
        
        stepper_1.setSpeedSteps( 5000, 500 );
        stepper_1.moveTo(20000);
        TimerUp = millis();
        while (stepper_1.moving()) {
          TimerPtr = &TimerUp;  //point to this timer
          TimerUpFlag = true;   //enable timing
          if (TimerUpFlag && millis() - TimerUp >= 250ul)
  
          TimerUpFlag = false; //disable timing
          TimerPtr = &dummy;   //pointer to dummy timer
          stepper_1.stop();
          Serial.println(stepper_1.readSteps());
                
      }
      break;
      
 
    //**********************
    case 0xFFA05F:                                           // Buffer tank CCW jog
      {
        Serial.println("Buffer tank CCW jog");
        TimerPtr = &TimerDown;  //point to this timer
        TimerDownFlag = true;   //enable timing
        stepper_1.setSpeedSteps( 5000, 500 );
        stepper_1.moveTo(0);
        TimerDown = millis();
      }
      break;


    //**********************
    case 0xFF10EF:                                           // IPA tank CW jog
      {
        Serial.println("IPA tank CW jog");
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        stepper_2.setSpeedSteps( 5000, 500 );
        stepper_2.moveTo(20000);
        TimerUp = millis();
      }
      break;

    //**********************
    case 0xFF906F:                                           // IPA tank CCW jog
      {
        Serial.println("IPA tank CCW jog");
        TimerPtr = &TimerDown;  //point to this timer
        TimerDownFlag = true;   //enable timing
        stepper_2.setSpeedSteps( 5000, 500 );
        stepper_2.moveTo(0);
        TimerDown = millis();
      }
      break;
 
    //**********************
    case 0xFF827D:                                           //LEFT Arrow toggle on/off
      {
        Serial.println("LEFT");
        digitalWrite(leftLED, !digitalRead(leftLED));   //Toggle LED
      }
      break;
 
    //**********************
    case 0xFF02FD:                                           //RIGHT Arrow toggle on/off
      {
        Serial.println("RIGHT");
        digitalWrite(rightLED, !digitalRead(rightLED)); //Toggle LED
      }
      break;
 
     
    //**********************
    case 0xFFFFFFFF:                                          //Repeat code
      {
        
        *TimerPtr = millis();                                 //reset the current timer
      }
      break;
 
  } // END switch case
 
}
} 

use ctrl-T for autoformatting your code.
Make it a habit to press ctrl-T every few lines of code that you have written.

If you have your code autoformatted analyse carefully which lines are executed conditionally and which lines are executed unconditionally.

I bet your code prints the position only one time and not multiple times

Yep! That's exactly what it does. Because it's not checking back at the status I believe. And I'll try the ctrl-T.

I repeat myself:

Ok hmmmm. Let me think about this.

It is not so much thinking over
it is learning basics

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

Ok I see. I'll read this. Thanks for sending it.

This helped. Thanks for the tip. I can see that it organizes everything now.

Here's what I have now. Serial counts steps but only up to 5, then stepper stops. I believe the timer is running out and its unable to refresh. Am I missing a line in the WHILE statement?

    case 0x57E34BB4:  // Buffer tank CW jog
      {
        Serial.println(stepper_1.readSteps());
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        stepper_1.setSpeedSteps(5000, 500);
        stepper_1.moveTo(20000);
        TimerUp = millis();


        while (stepper_1.moving()) {
          if (TimerUpFlag && millis() - TimerUp >= 250ul) {
            TimerUpFlag = false;  //disable timing
            TimerPtr = &dummy;    //pointer to dummy timer
            stepper_1.stop();
            break;
          }
        }
      }
      break;

Full code -



// changed to home against hard stop, no limit switch, 2 steppers. IR remote


#define MAX8BUTTONS  // saves RAM because only 4 switches are used
#define MAX_STEPPER 6
#include <MobaTools.h>
#include "IRremote.h"


const int STEPS_PER_REV = 800;
const int POS_MAX = 20000;

// 40 meter positions---------------------------------------------------------------------------------------
const int BUFFER_TANK_FORTY_METER_POSITION = 5000;  // Buffer tank
const int IPA_TANK_FORTY_METER_POSITION = 3500;     // IPA tank
// 80 meter positions----------------------------------------------------------------------------------------
const int BUFFER_TANK_EIGHTY_METER_POSITION = 10000;  // Buffer tank
// 160 meter positions------------------------------------------------------------------------------------------
const int BUFFER_TANK_ONESIXTY_METER_POSITION = 16000;  // Buffer tank

//create stepper object ( 800 steps / rev - 1/4 microstep )---------------------------------------------------------

// Stepper 1 buffer tank
const byte stepper1_pul = 2;
const byte stepper1_dir = 3;
MoToStepper stepper_1(STEPS_PER_REV, STEPDIR);

// Stepper 2 IPA tank
const byte stepper2_pul = 4;
const byte stepper2_dir = 5;
MoToStepper stepper_2(STEPS_PER_REV, STEPDIR);

const byte enaPin = 7;



// create names for the buttons--------------------------------------------------------------------------------------------
// buttons must switch to Gnd
enum { buttonZero,
       buttonCW,
       buttonCCW,
       forty_meter_button,
       eighty_meter_button,
       onesixty_meter_button };
const byte buttonPins[] = { 22, 23, 24, 26, 27, 28 };  // assign pins to the buttons
const byte buttonCnt = sizeof(buttonPins);
MoToButtons myButton(buttonPins, buttonCnt, 20, 500);


// IR remote --------------------------------------------------------------------------------------------------
const byte RECV_PIN = 8;  //IR receive pin

IRrecv irrecv(RECV_PIN);  //create instance of 'IRrecv'
decode_results results;   //create instance of 'decode_results'

unsigned long TimerUp;  //UP arrow on the remote
boolean TimerUpFlag = false;

unsigned long TimerDown;  //DOWN arrow on the remote
boolean TimerDownFlag = false;

unsigned long dummy;
unsigned long* TimerPtr = &dummy;  //pointer to the current timer

const byte leftLED = 10;   //toggles on/off
const byte rightLED = 11;  //toggles on/off







// Setup--------------------------------------------------------------------------------------------------
void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  // Stepper 1
  stepper_1.attach(stepper1_pul, stepper1_dir);
  stepper_1.attachEnable(enaPin, 10, LOW);  // Enable active

  // Stepper 2
  stepper_2.attach(stepper2_pul, stepper2_dir);
  stepper_2.attachEnable(enaPin, 10, LOW);  // Enable active

  pinMode(LED_BUILTIN, OUTPUT);

  Serial.println("Starting loop");

  irrecv.enableIRIn();  //IR remote start receive
}



// reading and processing the buttons ( debouncing and state change detection)------------------------------------------
void loop()

{
  myButton.processButtons();


  // check buttons and react accordingly
  if (myButton.pressed(buttonZero)) {  // home all steppers to zero position
    Serial.println(" Find ref point");
    toRefPoint();
  }
  if (myButton.pressed(buttonCW)) {  // jog slow clockwise direction
    Serial.println("Jog CW towards end");
    toCWdirection();
  }
  if (myButton.pressed(buttonCCW)) {  // jog slow counter clockwise direction
    Serial.println("Jog CCW back to 0 ");
    toCCWdirection();
  }
  if (myButton.pressed(forty_meter_button)) {  // move to 40m position
    Serial.println("Move towards the 40M position");
    toFortyPoint();
  }
  if (myButton.pressed(eighty_meter_button)) {  // move to 80m position
    Serial.println("Move towards the 80M position");
    toEightyPoint();
  }
  if (myButton.pressed(onesixty_meter_button)) {  // move to 160m position
    Serial.println("Move towards the 160M position");
    toOnesixtyPoint();
  }

  if (myButton.released(buttonCW) || myButton.released(buttonCCW)) {
    Serial.println("Stop the stepper");
    stepper_1.rotate(0);
  }



  // IR remote controls------------------------------------------------------------------------------------------
  if (irrecv.decode(&results))  //is there IR remote button code
  {
    //Serial.println(results.value);
    processButton();  //process button press
    irrecv.resume();  //restart for next button press
  }


  // Jogging stop timers---------------------------
  //**********************                                // CW button release
  //if timing is enabled, is it time to stop
  if (TimerUpFlag && millis() - TimerUp >= 250ul) {
    TimerUpFlag = false;  //disable timing
    TimerPtr = &dummy;    //pointer to dummy timer
    stepper_1.stop();
    stepper_2.stop();
  }

  //**********************                                // CCW button release
  //if timing is enabled, is it time to stop
  if (TimerDownFlag && millis() - TimerDown >= 250ul) {
    TimerDownFlag = false;  //disable timing
    TimerPtr = &dummy;      //pointer to dummy timer
    stepper_1.stop();
    stepper_2.stop();
  }
}




// Homing: move all steppers to ref point and set zeropoint----------------------------------------------------------------------------
void toRefPoint() {

  Serial.println("homing buffer tank...");  // buffer tank start homing...
  stepper_1.setSpeedSteps(20000, 200);
  stepper_1.doSteps(-18000);
  while (stepper_1.moving()) {
    Serial.println(stepper_1.readSteps());
  }
  delay(1000);
  Serial.println("hard stop reached, now move forward a small bit");
  stepper_1.doSteps(100);
  while (stepper_1.moving()) {
    Serial.println(stepper_1.readSteps());
  }
  Serial.println("now set zero");
  stepper_1.setZero();
  stepper_1.moveTo(0);
  while (stepper_1.moving()) {
    Serial.println(stepper_1.readSteps());
  }
  Serial.println("buffer tank homing finished!");
  delay(1000);



  Serial.println("homing IPA tank...");  // IPA tank start homing...
  stepper_2.setSpeedSteps(20000, 200);
  stepper_2.doSteps(-2000);
  while (stepper_2.moving()) {
    Serial.println(stepper_2.readSteps());
  }
  delay(1000);
  Serial.println("hard stop reached, now move forward a small bit");
  stepper_2.doSteps(100);
  while (stepper_2.moving()) {
    Serial.println(stepper_2.readSteps());
  }
  Serial.println("now set zero");
  stepper_2.setZero();
  stepper_2.moveTo(0);
  while (stepper_2.moving()) {
    Serial.println(stepper_2.readSteps());
  }
  Serial.println("buffer tank homing finished!");
}


// 40 meter position-------------------------------------------------------------------------------------------------
void toFortyPoint() {
  {  // buffer tank 40 meter position
    stepper_1.setSpeedSteps(40000, 500);
    stepper_1.moveTo(BUFFER_TANK_FORTY_METER_POSITION);
    while (stepper_1.moving())
      Serial.println(stepper_1.readSteps());
  }
  delay(1000);
  {  // IPA tank 40 meter position
    stepper_2.setSpeedSteps(40000, 500);
    stepper_2.moveTo(IPA_TANK_FORTY_METER_POSITION);
    while (stepper_2.moving())
      Serial.println(stepper_2.readSteps());
  }
}

// 80 meter position------------------------------------------------------------------------------------------------------
void toEightyPoint() {  // buffer tank 80 meter position
  stepper_1.setSpeedSteps(40000, 500);
  stepper_1.moveTo(BUFFER_TANK_EIGHTY_METER_POSITION);
  while (stepper_1.moving())
    Serial.println(stepper_1.readSteps());
}

// 160 meter position-------------------------------------------------------------------------------------------------------
void toOnesixtyPoint() {  // buffer tank 160 meter position
  stepper_1.setSpeedSteps(40000, 500);
  stepper_1.moveTo(BUFFER_TANK_ONESIXTY_METER_POSITION);
  while (stepper_1.moving())
    Serial.println(stepper_1.readSteps());
}


// CW jog buttons-------------------------------------------------------------------------------------------------------------
void toCWdirection() {  // buffer tank jog CW
  stepper_1.setSpeedSteps(5000, 500);
  stepper_1.moveTo(20000);

  while (stepper_1.moving()) {  // <<<= opening curly brace
    // reading in the state of the button again and again and again
    // how should your code "know" if a button is pressed or released LATER
    // The only way is to read-in the button-state
    // again and again and again I_N_S_I_D_E the while-loop
    myButton.processButtons();  // <<< read-in button-states

    if (myButton.released(buttonCW)) {
      stepper_1.stop();
      break;
    }
    Serial.println(stepper_1.readSteps());
  }
}


// CCW jog buttons------------------------------------------------------------------------------------------------------------
void toCCWdirection() {  // buffer tank jog CCW
  stepper_1.setSpeedSteps(5000, 500);
  stepper_1.moveTo(0);

  while (stepper_1.moving()) {  // <<<= opening curly brace
    // reading in the state of the button again and again and again
    // how should your code "know" if a button is pressed or released LATER
    // The only way is to read-in the button-state
    // again and again and again I_N_S_I_D_E the while-loop
    myButton.processButtons();  // <<< read-in button-states

    if (myButton.released(buttonCCW)) {
      stepper_1.stop();
      break;
    }
    Serial.println(stepper_1.readSteps());
  }
}


// IR remote button controls-----------------------------------------------------------------------------------------------
void processButton() {
  switch (results.value) {

    //**********************
    case 0x57E34BB4:  // Buffer tank CW jog
      {
        Serial.println(stepper_1.readSteps());
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        stepper_1.setSpeedSteps(5000, 500);
        stepper_1.moveTo(20000);
        TimerUp = millis();


        while (stepper_1.moving()) {
          if (TimerUpFlag && millis() - TimerUp >= 250ul) {
            TimerUpFlag = false;  //disable timing
            TimerPtr = &dummy;    //pointer to dummy timer
            stepper_1.stop();
            break;
          }
        }
      }
      break;







    //**********************
    case 0x57E331CE:  // Buffer tank CCW jog
      {
        Serial.println("Buffer tank CCW jog");
        TimerPtr = &TimerDown;  //point to this timer
        TimerDownFlag = true;   //enable timing
        stepper_1.setSpeedSteps(5000, 500);
        stepper_1.moveTo(0);
        TimerDown = millis();
      }
      break;


    //**********************
    case 0xFF10EF:  // IPA tank CW jog
      {
        Serial.println("IPA tank CW jog");
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        stepper_2.setSpeedSteps(5000, 500);
        stepper_2.moveTo(20000);
        TimerUp = millis();
      }
      break;

    //**********************
    case 0xFF906F:  // IPA tank CCW jog
      {
        Serial.println("IPA tank CCW jog");
        TimerPtr = &TimerDown;  //point to this timer
        TimerDownFlag = true;   //enable timing
        stepper_2.setSpeedSteps(5000, 500);
        stepper_2.moveTo(0);
        TimerDown = millis();
      }
      break;

    //**********************
    case 0xFF827D:  //LEFT Arrow toggle on/off
      {
        Serial.println("LEFT");
        digitalWrite(leftLED, !digitalRead(leftLED));  //Toggle LED
      }
      break;

    //**********************
    case 0xFF02FD:  //RIGHT Arrow toggle on/off
      {
        Serial.println("RIGHT");
        digitalWrite(rightLED, !digitalRead(rightLED));  //Toggle LED
      }
      break;


    //**********************
    case 0xFFFFFFFF:  //Repeat code
      {

        *TimerPtr = millis();  //reset the current timer
      }
      break;

      // END switch case
  }
}

Here's an updated version I've tried with the serial print inside the while loop. Still only moves and prints about 5 steps before stopping. -

void processButton() {
  switch (results.value) {

    //**********************
    case 0x57E34BB4:  // Buffer tank CW jog
      {
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        stepper_1.setSpeedSteps(5000, 500);
        stepper_1.moveTo(20000);
        TimerUp = millis();


        while (stepper_1.moving()) {
          if (TimerUpFlag && millis() - TimerUp >= 250ul) {
            TimerUpFlag = false;  //disable timing
            TimerPtr = &dummy;    //pointer to dummy timer
            stepper_1.stop();
            break;
          }
          Serial.println(stepper_1.readSteps());
        }
      }
          
      break;

This is a way too short description to understand what is really happening.
You said really nothing about times
how long does your stepper-motor rotate without printing
how long does your stepper-motor rotate with printing
how long do you press the IR-remote button

you did not analyse if your code is executing some other steps
and this kind of analysing is to print out to the serial monitor at many many places

If you are looking at how you try to develeop this project:

Until now you did NOT learn much basics
I guess you do a lot of assuminngs about how it might work
but you do not check if your assumings are right.

You can go on this way and it will take you weeks and months until you got it working by accident still not knowing what exactly made it work

or

you can learn the basics and then testing evering in TINY steps.
step by step and testing not only the regular case and quickly move on, but also check - what happens if I use number 0?
what happens if I use a higher speed?
what happens if I use a bigger number of steps?
etc. etc.
this will take its own hours to do
but at the end and in the long run it will save a lot of time

Though some people are just not patient enough to work this way
And prefer whirling in circles at high speed without really learning

another question does function moveTo run to relative or absolute coorcinates?

  • shouldn't TimerUp be reset to millis() when the timer expires?

  • why do you need a TimerUpFlag? do you only want the timer inside the while loop to run once?

  • why is there a break? Do you only want the while loop to run until the timer expires?

  • why do you need to execute stop()? won't the motor stop after doing the # of requested steps

why not

        TimerUp = millis ();
        while (stepper_1.moving ()) {
          if  (millis() - TimerUp >= 250ul)  {
              TimerUp = millis ();
              Serial.println (stepper_1.readSteps ());
          }
        }

Ok makes sense. I will think about the points you mentioned here. I've been reading about the basics you have sent earlier. Thank you for your help on this!

Ok I see. This gives me something to think about. After seeing your suggestion, I will be changing my whole approach on this. Thanks for your help!

the documentation of this function says
void myStepper.moveTo( long stepPos );
The motor will move to the position that is stepPos steps away from reference point

if you execute
stepper_1.moveTo(20000);

If your stepper-motor is at position 19999 This means
your stepper-motor will do one SINGLE step
and then reaches position 20000.

If your stepper-motor is at position 20010 This means
your stepper-motor will do 10 steps into the OPPOSITE direction
and then reaches position 20000.

Is this the behaviour that you want?

I guess you wanted a behaviour like: as long as you press the IR-remote button the stepper-motor shall rotate always into the same direction.

I hope you can see now that you have to read the documentation carefully
and then do tests like described above to prove if you understood the documentation right.

There are some more things to learn:

  • describing the wanted functionality with high precision

  • describing the observed behaviour with high precission

  • And at least answering questions ! Because these questions want to support you to be more precise
    SO I ask again:

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.