While Statement problem

I am currently making something like a slider using the 28BYJ-48 stepper motor with a lead screw and a rod. At the start of the slider I added a switch to act as an endstop. When the arduino gets powered up I want it to move in one direction until the platform of the slider hits and turns on the switch. I tried making a while statement that moves the stepper one step at a time while the button state is low and stops when it gets high and then the code in the loop (which I have not made yet)starts, but it doesn’t work i think it only ckecks the condition once in the beginning. I would appreciate any guidance! Thanks a lot!

#include <Stepper.h>
// Define number of steps per rotation:
const int stepsPerRevolution = 4096; // one full rotation is 2048 steps
int endStop = 3;
int endstopValue = 0;

// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {

myStepper.setSpeed(8);
pinMode(endStop, INPUT);
Serial.begin(9600);
endstopValue = digitalRead(endStop);
Serial.println(endstopValue);

while(endstopValue == LOW){
  digitalRead(endStop);
  myStepper.step(1);
}

}
void loop() {
// Step one revolution in the other direction:
/*Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
Serial.println(endstopValue);

// Step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
Serial.println(endstopValue);
*/

}

Your program is short so please include it in your Post so that we don’t have to download the file. Please also use the code button </>.

…R

I did

nikolas550:
I did

Nope

while(digitalRead(endStop) == LOW){
   myStepper.step(1);
 }

It doesn’t compile now for some reason
It says:
exit status 1
Error compiling for board Arduino Nano.

#include <Stepper.h>
// Define number of steps per rotation:
const int stepsPerRevolution = 4096; // one full rotation is 2048 steps
int endStop = 3;
 

// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
  
  myStepper.setSpeed(8);
  pinMode(endStop, INPUT);
  Serial.begin(9600);
  
  
  while(digitalRead(endStop) == LOW){
    
    myStepper.step(1);
  }
  
}
void loop() {
  // Step one revolution in the other direction:
  /*Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  Serial.println(endstopValue);
  
  // Step one revolution in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  Serial.println(endstopValue);
  */
  
}[code]

[/code]

It says:
exit status 1

I bet it says a whole lot more.
Don’t make us guess

As I said above it doesn't only say" exit status 1"it says

"exit status 1
Error compiling for board Arduino Nano. "

Is that the whole error message copied using the "Copy error messages" button in the IDE ?

What line does it say exit status -1 after?

Post the complete error message, to include where it is occurring.

I just compiled that code in IDE 1.8.4 for a Nano, compiled ok once I took
the extra code tag off the end.

Compiles without error in 1.8.5 also.

How about using

pinMode(endStop, INPUT_PULLUP);

I got it working! Thank you everyone for the help!

…and the errors?