Easy Driver with Stepper run time buttons

Hi there.

I have a stepper running with a POT for variable speed, using the Sparkfun Easy Driver.

I want to step this up a notch (no pun) and ad 3-5 buttons with set run times associated to them. The idea is that I can run the stepper for the full amount of steps (this is a dolly on a track so there would be a max amount of steps to count) and with the buttons specify the speed.

Example
Button 1 - 5 mins and full amount of steps
Button 2 - 15 mins and full amount of steps
Button 3 - 30 mins " " "
Button 4 - 45 mins --- so on an so forth

#define DIR_PIN 2
#define STEP_PIN 3
#define switchPin 4

// show me steps and delay
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

Below is the code I am currently using - any thoughts on this folks?
The way I see it i need to add a function that counts the steps first, and then define it.
Add the button and do the math with the amount of steps, then calculate the speed it needs to run for each button.

But this is beyond me right now.


void setup() {
  Serial.begin(9600);
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode (switchPin, INPUT);

  // Show me power on LED
  pinMode(ledPin, OUTPUT);    
}

void loop(){
  rotate();//will rotate 2 times, with Pot control 

}

void rotate(){
  /// LED lights with 9volt power on
  digitalWrite(ledPin, HIGH);
  if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
    digitalWrite(DIR_PIN,HIGH);
    // Serial.println("Fwd");
  }
  else { // if the swtich is LOW, rotate counter clockiwise
    digitalWrite(DIR_PIN,LOW);
    //  Serial.println("Rev");
  }

  for(int i=0; i < 1600 * .125; i++){
    int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
    usDelay = constrain(usDelay, 10, 7000);

    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(usDelay);

    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(usDelay);


  }

}

You need to change the concept of your code so that loop() has at least two functions - one to read the value of the buttons (or the potentiometer) and store that value and the second to move the stepper based on that value. The code for moving the stepper should do nothing new if the value hasn't changed.

You are planning some very slow movements. Do you want a new button press to abort a movement in progress and start a new movement or do you want buttons to be ignored until the movement completes?

...R

Hi R.

Well I would say using the POT while running a button setting should over-ride the button (in case I want to speed or slow the dolly down)

The trick is going to have to be that the dolly is at the end of the track before pressing a button, so would the step count have to be reset at this point (dont want to waste battery power sending the dolly to a start position in the case of stopping halfway through)

Would the button readings be a variable that is called on press of the button to set the POT speed? What id it was just one button with numerous states - press 3 times for 45min, press twice for 30 etc.

Another thought would be a dampening equation to ramp from start to finish and between clicks to ease into the speed change??? :slight_smile:

Thoughts?
I dont mind recoding from scratch at this point to gain this control

It may be a good idea to keep a list of the refinements you will eventually implement but don't allow them to confuse you at this stage.

First requirement is to make a very simple sketch that controls the speed setting with the pot (which you already have) and controls the movement (i.e. the generation of steps) using the buttons. In my earlier post I suggested two functions within loop(). In this case you need 3 - read pot, read buttons, move motor.

I don't understand why you have this

  for(int i=0; i < 1600 * .125; i++){

In my concept there is no need to limit the number of steps as the operator will (presumably) release the button. And from what you have said so far there is no need to count the steps to identify the position of the dolly - presumably the operator will do that visually.

Also, in the above snippet you are trying to do floating point maths on integers - that will give strange results.

You might decide to put limit detection switches at each end of the track so that the Arduino would automatically stop sending unwanted pulses.

You should be aware that a stepper motor is always using power, even when stationary.

You have your long delay both while the pulse is high and while it is low. It would be better to have a short high pulse (100 microseconds would probably be sufficient) and put all the delay between pulses.

As you are having long delays (for slow movement) using the delay() function will tie up the Arduino unnecessarily so it can't do anything else (including reading buttons). Look at the concept in the "blink without delay" example for how to get around this.

...R

This is microstepping the stepper 1600 steps p/r and a 1/4 turn to detect if the forward or reverse button is clicked

  for(int i=0; i < 1600 * .125; i++){

Thank you for the thoughts here.
I will start by adding the extra functions to read the buttons - am I not already reading the pot and move motor though with rotate(); ?

Just to give an idea why the delay is in there is that I run this track along a 3 foot length with speed ranging from 5mins to 4hours

Would you happen to have a function handy to simply run the track for a specific amount of time that I can start with?

I understand why you have long delays. It's just that the pulse should be short regardless of how fast or slow the motor is to move. The pulse just tells the driver "please make a step".

I know you are already reading the pot (I did acknowledge that) - it's just that you need to change where that happens in your code so that (like reading the buttons) it is separate from moving the motor.

If you separate the different parts you won't need to bother with " a 1/4 turn to detect if the forward or reverse button is clicked". Each iteration through loop() (tens or hundreds of thousands per second) will check the buttons and the pot.

To run for a specified time you need something like this (bearing in mind that variables that store the value of millis() must be declared as unsigned long. Just record the time when you start the move and keep checking the elapsed time with the total time that you require.

startOfRun = millis();

if (millis() - startOfRun < milliSecsForRun) {
    moveMotor{}
}

...R

Hi so I have come up with the below code.
It works as follows

Switch pin is HIGH or LOW
HIGH runs the ramp funtion
LOW runs the pot function

Pot function stores a reading from the POT and assigns motorSpeed val x 100 to ramps var of pos (amount of steps).
This way when the switch is in LOW I can set the motor speed when the switch is set to HIGH ramp now uses that value.
Kinda COOL!
Next step would to be assign the setMaxSpeed and setMaxAcceleration values.
What I need help is being sure that the stepper only steps as many steps as the track is long

Make sense? ANy thoughts???

#include <Stepper.h>



#include <AccelStepper.h>


// Define a stepper and the pins it will use
AccelStepper stepper(4, 3, 2);

// pot
const int stepsPerRevolution = 1600;  // change this to fit the number of steps per revolution for your motor

//Stepper myStepper(stepsPerRevolution, 4,3,2); 
int stepCount = 0;  // number of steps the motor has taken
#define DIR_PIN 2
//#define STEP_PIN 3
#define switchPin 4
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

int fwdstepCount = 0;         // number of steps the motor has taken forward
int revstepCount = 0;         // number of steps the motor has taken forward

int motorSpeed = 0;
int pos = 0; // number of steps in ram




void setup()
{ 
  Serial.begin(9600);
  digitalWrite(ledPin, HIGH); 
  // Show me power on LED
  pinMode(ledPin, OUTPUT);
  pinMode (switchPin, INPUT);
  // read the sensor value:

   stepper.setMaxSpeed(3000);
 stepper.setAcceleration(1000);
}


void loop()
{
  if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
   ramp();
   // Serial.print("REVsteps:" );
   // Serial.println(fwdstepCount);
   // fwdstepCount++;
  }
  else { // if the swtich is LOW, rotate counter clockiwise
    digitalWrite(DIR_PIN,LOW);
    pot();
}
}

void ramp(){
//pos = motorSpeed;
  if (stepper.distanceToGo() == 0)
  {
    delay(500);
    pos = -pos;
    stepper.moveTo(pos);
       Serial.println(pos);
  }
  stepper.run();
}

void pot(){
// read the sensor value:
  int posVal = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(posVal, 0, 1023, 0, 100);
  // set the motor speed:
  if (motorSpeed > 0) {
    stepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    //myStepper.step(stepsPerRevolution/100);
  //int posVal;
  pos=motorSpeed*100;
   Serial.println(motorSpeed);
  } 
}

What I need help is being sure that the stepper only steps as many steps as the track is long

I mentioned earlier that you might put limit switches at the ends of the track.

You could work out how many steps it takes to traverse the whole track but you will still need at least one limit switch so that your code can send the stepper motor to a known starting position.

I find it hard to follow your code. It would be easier to follow if it was organized better into functions. But I'm sure a lot of my code would be just as hard to follow - especially as I evolve a concept. And if it is only for me there is not a lot of point tidying it up after it works - that just introduces more opportunity for error. On the other hand if I spend a bit of time thinking/planning what functions are needed it makes writing and debugging the code easier. A pencil and paper can be a great asset because they force you to stay with generalities.

...R

Hey thanks, yes I agree tidy organised code is key!
I have started seperating this into functions called by a push button and switch.
As for sending the stepper to a start position, I dont really want to do that as it would drain battery power in the field.
All I really need to do is know the amount of steps for the track, then calculate it with the POT value - then display it in Hours / Mins / Secs on the LCD - any thoughts on this Equation?

Maybe the below is easier to follow and decipher?

#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 9, 8, 7, 6, 5);

/////// button //////////////////////////////////////
const int buttonPin = 12;     // the number of the pushbutton pin
const int ledBTNPin =  11;      // the number of the LED pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

/////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
#define DIR_PIN 2
#define STEP_PIN 3
#define switchPin 4

// show me steps and delay
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int fwdstepCount = 0;         // number of steps the motor has taken forward
int revstepCount = 0;         // number of steps the motor has taken forward
const int stepsPerRevolution = 1600; 


int stepcount = 3200;
int spd;
int Scount = 0;                     // count seconds                 
int Mcount = 0;                     // count minutes
int Hcount =0;                      // count hours
int Dcount = 0;                     // count days

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode (switchPin, INPUT);

  // Show me power on LED
  pinMode(ledPin, OUTPUT);    
}

void loop(){
BTN();
}

void rotate(){
  /// LED lights with 9volt power on
  digitalWrite(ledPin, HIGH);
  if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
    digitalWrite(DIR_PIN,HIGH);
    lcd.setCursor(15, 0);   
    lcd.print("R");
  }
  else { // if the swtich is LOW, rotate counter clockiwise
    digitalWrite(DIR_PIN,LOW);
     lcd.setCursor(15, 0);   
    lcd.print("F");
  }
//duration();
  for(int i=0; i < 1600 * .0125; i++){
    int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
    usDelay = constrain(usDelay, 10, 7000);

    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(usDelay);

    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(usDelay);
    spd=usDelay/10; // how do I conver this to hours mins and secs?
    // need a step amount to calculate spd by steps = duration

  }

}

void duration(){
    int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
    usDelay = constrain(usDelay, 10, 7000);
    spd=usDelay/10;
         lcd.setCursor(0,0);                // sets cursor to 3rd line
  lcd.print ("SPD:");
        lcd.setCursor(5,0);
            lcd.print(spd);
}



void BTN(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:  POT  
    digitalWrite(ledBTNPin, LOW); 

  //  pot();
   duration();
   //rotate();
  } 
  else {
    // turn LED off: RAMP
    digitalWrite(ledBTNPin, HIGH); 

    LCD();
    rotate();//will rotate a 1/2 turn, with Pot control 
  //  ramp();
  //  stepper.run();  

  }
}



void LCD(){
        
  if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
         lcd.setCursor(0,0);                // sets cursor to 3rd line
  lcd.print ("SPD:");
        lcd.setCursor(5,0);
            lcd.print(spd);
   // lcd.setCursor(15, 0);   
   // lcd.print("R");
    lcd.setCursor(0, 1);   
    lcd.print("S>");
    lcd.setCursor(2, 1);
    lcd.print(stepsPerRevolution);
    lcd.setCursor(8, 1);   
    lcd.print("A>");
    lcd.setCursor(10, 1);
    lcd.print("ON");
  }
  else { // if the swtich is LOW, rotate counter clockiwise
         lcd.setCursor(0,0);                // sets cursor to 3rd line
  lcd.print ("SPD:");
        lcd.setCursor(5,0);
            lcd.print(spd);
   // lcd.setCursor(15, 0);   
   // lcd.print("R");
    lcd.setCursor(0, 1);   
    lcd.print("S>");
    lcd.setCursor(2, 1);
    lcd.print(stepsPerRevolution);
    lcd.setCursor(8, 1);   
    lcd.print("A>");
    lcd.setCursor(10, 1);
    lcd.print("OFF");
  }
}

Moving the stepper will make little or no difference to power consumption unless you routinely disconnect power from the motor and rely on friction to hold position.

You probably only need to move the motor to the end stop to establish the absolute position once during a session, or anytime that you feel steps have been missed.

I suspect you can only figure out the total number of steps for the length of the track by trial and error. However without a home position switch the number won't mean a lot.

I would go for a limit switch at each end. Then, regardless of what the operator tries to do the software will know to stop sending pulses if the switch is pressed.

Sorry, but the code is more confusing than ever now. The previous versions didn't have any LCD stuff. And I've taken the trouble to copy it into my editor where it is easier to see.

Why do you have "const int buttonPin = 12;" in one place and "#define DIR_PIN 2" in another place? Stick to one style or the other.

Moving the code that was previously in loop() without doing anything else to the code probably reduces clarity.

If it were my code I think I would build loop() like this ...

void loop() {
   readButtons; // all the buttons and switches and pots
   moveMotors();
   writeLCD();
}

...R

Robin thank you!

As I am getting better with all of this, I still need guidance are you are helping so much.
From my experience though with this, I found that putting an LCD readout into the loop slowed the Arduino (and motor) down as it was writing to the LCD and sending pulses to the motor at the same time.

What I have done is just put my read button function in the loop, the button calls the run motor function, button off calls the LCD and pauses the motor.

What the LCD shows is the POT reading converted to minutes which is exactly what I need. It is a variable called "spd".

Having said that, do you know of a way to count down the minutes once the track is running? Can be on a new line on the LCD and if i pause the motor the counter pauses too.
You will see what I have tried with the timer function, if I could get it to use "spd" and count it down it would be awesome!

Here is my code (sorry its a bit messy right now)

#include <elapsedMillis.h>
elapsedMillis timer0;
#define interval 1000 // the interval in mS 


#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 9, 8, 7, 6, 5);




/////// button //////////////////////////////////////
const int buttonPin = 12;     // the number of the pushbutton pin
const int ledBTNPin =  11;      // the number of the LED pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

/////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
#define DIR_PIN 2
#define STEP_PIN 3
#define switchPin 4

// show me steps and delay
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int fwdstepCount = 0;         // number of steps the motor has taken forward
int revstepCount = 0;         // number of steps the motor has taken forward
const int stepsPerRevolution = 1600; 


int stepcount = 3200;
int spd;
int Scount = 0;                     // count seconds                 
int Mcount = 0;                     // count minutes
int Hcount =0;                      // count hours
int Dcount = 0;                     // count days

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(DIR_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode (switchPin, INPUT);

  // Show me power on LED
  pinMode(ledPin, OUTPUT);  
  // ellapsed timer
  timer0 = spd; // clear the timer at the end of startup  
}

void loop(){
  BTN();
}
void timer(){ // I need to convert timer0 to the spd value and have it change and count down!!!
  if (timer0 > interval) {
    timer0 -= interval; //reset the timer
   // int ledPin = digitalRead(led);
    // read the current state and write the opposite
    lcd.setCursor(0, 1);   
    lcd.print("T>");
    lcd.setCursor(2, 1);
    lcd.print(timer0);

  }
}
void rotate(){
  /// LED lights with 9volt power on
  digitalWrite(ledPin, HIGH);
  if (digitalRead(switchPin)){ //if the switch is HIGH, rotate clockwise
    digitalWrite(DIR_PIN,HIGH);
    lcd.setCursor(13, 0);   
    lcd.print("REV");
  }
  else { // if the swtich is LOW, rotate counter clockiwise
    digitalWrite(DIR_PIN,LOW);
    lcd.setCursor(13, 0);   
    lcd.print("FWD");
  }
  for(int i=0; i < 1600 * .0125; i++){
    int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
    usDelay = constrain(usDelay, 10, 7000);

    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(usDelay);

    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(usDelay);
    // each increment of 10 is about 3.4 mins
    // below is POT val x .03428 - 3.4 mins is fastest runtime 
    //or 4Hrs 240 mins / 70000 = 0.03428 - LCD displays 240 mins :)
    spd=usDelay*.03428; // how do I conver this to hours mins and secs?
    // need a step amount to calculate spd by steps = duration

  }

}

void duration(){
  int usDelay = map(analogRead(A0), 10, 1000, 10, 7000);
  usDelay = constrain(usDelay, 10, 7000);
  spd=usDelay*.03428;
  lcd.setCursor(0,0);                // sets cursor to 3rd line
  lcd.print ("SPD:");
  lcd.print(spd);
  lcd.setCursor(8,0);
  lcd.print("mins");
  lcd.setCursor(6, 1);
  lcd.print("PAUSE");
}



void BTN(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // BUTTON PUSHED track pause track 
    digitalWrite(ledBTNPin, LOW); // may not need this

    //  pot();
    //LCD(); // displays values from LCD():
    //lcd.setCursor(0,0);                // sets cursor to 1st line
    //lcd.print ("+SPD:");
    //lcd.setCursor(5,0);
    //lcd.print(spd);
    duration(); // allows pot rotation and values / pauses motor
    //rotate();
  } 
  else {
    // BUTTON  NOT PUSHED track running
    digitalWrite(ledBTNPin, HIGH); // may not need this
    // TURN LCD off in final here - no display while tracking
    //LCD(); // displays values from LCD();
    //lcd.clear();
      lcd.setCursor(0,0);                // sets cursor to 3rd line
  lcd.print ("SPD:");
  lcd.print(spd);
  lcd.setCursor(8,0);
  lcd.print("mins");
  lcd.setCursor(6, 1);
  lcd.print("TRACKING");
    rotate();// runs the motor using pot value from duration();  
  }
}



void LCD(){
// what is doing for me?
  if (digitalRead(switchPin)){ 
    // BUTTON  NOT PUSHED track running
    lcd.setCursor(0,0);                // sets cursor to 1st line
    lcd.print ("+SPD:");
    lcd.setCursor(5,0);
    lcd.print(spd);
    // lcd.setCursor(15, 0);   
    // lcd.print("R");
   // timer();
  }
  else { // if the swtich is LOW, rotate counter clockiwise
  //BUTTON PRESSED - pause track
   // timer();
    lcd.setCursor(0,0);                // sets cursor to 1st line
   // lcd.print ("SPD:");
   // lcd.setCursor(5,0);
   // lcd.print(spd);
    // lcd.setCursor(15, 0);   
    // lcd.print("R");
   // lcd.setCursor(0, 1);   
   // lcd.print("S>");
   // lcd.setCursor(2, 1);
   // lcd.print(stepsPerRevolution);
   // lcd.setCursor(8, 1);   
   // lcd.print("A>");
    lcd.setCursor(6, 1);
    lcd.print("PAUSE");
  }
}

graphections:
I found that putting an LCD readout into the loop slowed the Arduino (and motor) down as it was writing to the LCD and sending pulses to the motor at the same time.

I understand that problem, though I have no experience with an LCD. The solution (IMHO) is to have a flag that the LCD function can use to decide whether to write or not. The flag could be set before the motor starts and could be cleared when the motor finishes. Perhaps you can reduce the amount the LCD writes at any single occasion so that short writes would fit between motor steps? There must be a pretty long gap between steps as you want the motor to move slowly.

Maybe you need to reorganize the code so that each run through loop() just does a single step?

...R

Robin

I am ok with the BTN press to read display the LCD, I really dont want or need it on at all times - just to set up the duration.

What I am currently working on is some way for a timer function to read my spd variable display it when I call the LCD and count it down and once done, stop the stepper :slight_smile:

Any thoughts on that?

I don't know what problem you have with the countdown ...

I think you said that you get a value from the pot and convert that to minutes and seconds.

I would save the value from the pot (which is just a number from 0 to 1023) and use that (or some multiple of it) for the countdown. Suppose that 300 corresponds to 5 minutes or 300 seconds.

If you save millis() at the start then the numbers should decrease from 300 to 299 to 298 etc when millis() - startMillis >= 1000, 2000 etc.

If you do it like this very crude pseudo code, you can count time continuously without missing any moments.

secsStillToRun = 300
decrementMillis = 1000
nextDecrement = 0
startMillis = millis()

loop() {
   if (millis() - startMillis >= nextDecrement) {
       if (! pause) {
           secsStillToRun = secsStillToRun - 1
       }
       nextDecrement = nextDecrement + decrementMillis
  }
}

When the secsStillToRun gets to 0 stop the motor. If you want a pause just include a flag (I've called it pause) that prevents the number being reduced.

...R

Hey Robin this is great - thank you!

1 Question though, how would I convert millis into minutes, the duration is never fast enough for seconds, everything is done in minutes.

I have made this a function that is called in the loop.

//int secsStillToRun = startMillis(10 * 60 * 1000); // original var - now using spd
int decrementMillis = 1000; // convert this to Mins??
int nextDecrement = 0;
int startMillis = millis();
int pause = 0;

void countdown(){
    lcd.setCursor(0, 1);   
    lcd.print("T>");
    lcd.setCursor(2, 1);
    lcd.print(spd);
   if (millis() - startMillis >= nextDecrement) {
       if (! pause) {
           spd = spd - 1;
       }
       nextDecrement = nextDecrement + decrementMillis;
  }
}

1 Question though, how would I convert millis into minutes, the duration is never fast enough for seconds, everything is done in minutes.

I'm not 100% certain I understand your question. The millis() function can not be converted to minutes. The difference between two calls to millis() could.

unsigned long firstTime = millis();
// do something that takes a really, really, really long time
unsigned lone secondTime = millis();

unsigned long interval = secondTime - firstTime;
unsigned long seconds = interval / 1000;
unsigned long minutes = seconds / 60;

Hi Paul

I am displaying the POT value as a variable called spd then I have mulitplied buy the lenth of time the track runs at its fastest - just to give a value - thus the equation gives me 5mins. WHen pot value changes I go up to 314mins

spd=useDelay*.045

What I would like is the counter to read "spd" and count down for me on another line on the LCD. This variable is called lcdSPD.

When the counter has counted all the way down I would like the stepper to stop.

ANy ideas?

What I would like is the counter to read "spd"

I wish I understood this. What counter? Why is spd in quotes? Why could a counter read speed?

I don't think counter is the correct terminology.

Paul I think youre over thinking this :wink:

spd = Poteniometer value x.0348 which equals time to travel in Mins (dont worry about this number, I know it)

I need spd after equation such as 318mins to count down from said spd variable which is a number of minutes to count down to zero and stop the stepper

Would changing counter to countdown be a better terminology to use? make more sense?

Forget all names of vars
think
count down from a number of minutes to zero and stop stepper motor

:slight_smile:

In my opinion it is you (@graphections) who are coming at this the wrong way.

Get your program to work using millis and work out a calculation that gives you minutes to show on your display. In other words the real action happens in millis and the conversion to minutes is just for the poor humans whose brains are too slow.

Maybe the start point for this is to change from "potVal * 0.348 = minutes" to "potVal * 20880 = millisecs"

So the countdown works through the millis and every so often you take the current value of the count down and calculate the minutes equivalent to show on the display.

Generally speaking what you see on a computer screen is only an illusion representing what is going on behind the scenes.

...R