Help with stepper motor, two buttons and an lcd

hi guys i made this program that allows me to run a stepper motor " doing few steps cw and ccw" for a certain amount of time by pushing a button and stopping the process by pushing another button a "stop button",

what i want to do now is add an lcd to show when i press button it says "movement cycle" and "decount of time" then when i press stop button i want the lcd to show " stoppage time"

You need to post your program.

Also post a link to the datasheet for your stepper motor and tell us what stepper motor driver you are using.

...R
Stepper Motor Basics
Simple Stepper Code

this is my stepper motor: 42BYGHW811
this is my driver : A4988 also im using “stepperdriver.h” library

this is my code :

#include <elapsedMillis.h> 
#include <StepperDriver.h>
int motor_steps = 200;  //
int step_divisition = 1;
int en_pin = 6;
int cw_pin = 4;
int clk_pin = 5;
const int buttonPin = 8;
const int buttonPinstop = 9;
int buttonState = 0;
int buttonStatestop = 0;
StepperDriver ss(motor_steps, step_divisition, en_pin, cw_pin, clk_pin);
unsigned int period =5000; 
//unsigned int period2 =2000;
const byte interruptPin = 2;
volatile int buttonFlag;
void setup() {
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(buttonPinstop, INPUT);

}

void loop() {
 

  elapsedMillis timeElapsed;
   buttonState = digitalRead(buttonPin);
  buttonStatestop = digitalRead(buttonPinstop);
    if (buttonState == HIGH) {
    while(timeElapsed < period && buttonStatestop == LOW) {
      Serial.println("test1");
      ss.setSpeed(180);
      ss.step(400);
      delay(400);
      ss.step(-400);
      delay(400);
      buttonState = digitalRead(buttonPin);
      buttonStatestop = digitalRead(buttonPinstop);
     
     }  

    }
     
}

Have you tried writing a short program that just shows Hello World on the LCD? If not that should be your first step.

It would also be a good idea to remove all blocking code from your program - such as WHILE and (I suspect) ss.step(400); (but I am not familiar with the library you are using).

Use IF and allow loop() to do the repetition if you want a responsive program. Look at the second example in my earlier link.

...R

when i use IF i need to stay pushing on the button for the motor to run when i stop pushing the motor stops, when i use while i only push once

CactusJack:
when i use IF i need to stay pushing on the button for the motor to run when i stop pushing the motor stops, when i use while i only push once

Then you need to change the code so it does stay working when you use IF.

For example press the button and save the button state in a variable.

...R

oh geez man i don't know how to do that :o

CactusJack:
oh geez man i don't know how to do that :o

if (taskComplete == true) {
   buttonState = digitalRead(buttonPin);
   if (buttonState == LOW) {   // assumes LOW when pressed
       taskComplete = false;
       // do stuff
   }
}

...R