ADDING PUSH BUTTON SWITCH

Added push button to avoid loop when board is powered up. Can't get buttonSW1 to start loop when needed. Need help.

#include <Stepper.h>
byte buttonSW1 = 2; // connect to ground and pin2

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

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(120);

pinMode(buttonSW1, INPUT_PULLUP );

Serial.begin(9600);

exit(0);

Serial.println("prress the buttonSW1 to bypass exit(0)");
while (digitalRead(buttonSW1)) {}
}
void loop()
{
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(1);

// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(1);
}

You should check status of button before calling exit

I have no idea what exit(0) is supposed to do, but whatever it is, surely it's over and done with by the time you get to the while()?

I normally do it the same as you but with no exit(0); It gets to the while() and sits there until the pin goes low, then heads off to loop().

(Assuming the switch is correctly wired to ground.)

ASIEGMAR:
Added push button to avoid loop when board is powered up. Can't get buttonSW1 to start loop when needed. Need help.

Sure do!

Firstly, correct the subject title in your first post - all caps indicates you do not understand how to use forums. :astonished:

Now you need to go and read the forum instructions so that you can go back and modify your original posts (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code" it can easily be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.


Now the specific problems.

The "exit(0);" is nonsense. Not sure what you are trying to do. Have another go at explaining it. :grinning:

Explain to us what you mean by "avoid loop when board is powered up"?

Actually, please sit down and just write down - for yourself as much as us - a clear description of what it is you actually want this program to do. Step by step. What do you want to happen when it starts, and what does it need to do under which particular conditions?

Seems to me it would be easier to accomplish by doing something like

void loop()
If buttonpushed == 0
read the button
If pushed, set buttonpushed to 1
Else if buttonpushed == 1
Do the stuff you want delayed til after the button is pushed