Newbie- How to I start a loop with a button push

Very new to all this. I really only want to learn how to do this to complete a project I have designed, do not want to become a coder, so please go easy on me.

Trying to get this code to start the loop one time with the push of a button. And if the button is not pushed, I want nothing to happen. Can not get it to do it. I know I am probably missing something very obvious to the forum.

Here it is, and thanks for the help:

#include <Stepper.h>
int stepsPerRevolution = 1600; // number of steps per revolution
int cameraFirePin = 2; //fires camera shutter
int numMoveRight = 3; //moves table right on axis
int numMoveLeft = 3; //moves table left on axis
int buttonPin = 7; //defines pin as button
int buttonState = 0; // defines button value as 0
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); // initialize the stepper library on pins 8 through 11:
void setup() {
** myStepper.setSpeed(60); // set the speed at 60 rpm:**
** pinMode(buttonPin, INPUT); // set the pin for button as INPUT**

}
void loop(){

** buttonState = digitalRead(buttonPin);**
** if (buttonState == HIGH); { //run the loop**

** for(int j=1; j<=numMoveRight; j=j+1 )**

** myStepper.step(6000); // rotate(clockwise):**
** delay(3000);**
** digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board**
** delay(3000);**
** digitalWrite(cameraFirePin, LOW); //does not fire camera shutter through relay board**

** for(int j=1; j<=numMoveLeft; j=j+1 )**

** myStepper.step(-6000); // rotate(counter clockwise):**
** delay(3000);**
** digitalWrite(cameraFirePin, HIGH); //fires camera shutter through relay board**
** delay(3000);**
** digitalWrite(cameraFirePin, LOW); //does not fire camera shutter through relay board**
** }}**
//end of steppermotorfunction

  1. Go read posting guidelines about how to properly post code. Use code tags when posting code.

  2. Go look at other examples of if statements, the reference section here is a good place to start. Look carefully. You picked up a little something extra in your if statement.

 if (buttonState == HIGH); {   //run the loop
 {
    for (int j = 1; j <= numMoveRight; j = j + 1 )
      myStepper.step(6000);    // rotate(clockwise):
    delay(3000);

What code line(s) should run numMoveRight times ?

As written

     myStepper.step(6000);    // rotate(clockwise):

will run that number of times whist subsequent lines of code will run once each time through loop() regardless of the for loop. Is that what you want ?

If you want a block of code to execute numMoveRight times then put it in a code block starting with { and ending with }

laughingcamera:
Very new to all this. I really only want to learn how to do this to complete a project I have designed, do not want to become a coder, so please go easy on me.

If you just want to get something to work and you are not interested in learning how to write programs then maybe you should ask in the Gigs and Collaborations section for someone to write the program for you and be prepared to pay.

...R

Sorry about the incorrect posting, I guess I forgot to attach the code instead of copy and paste, sorry. Robin2, took your suggestion and asking at Gigs and Collaborations. Thanks.

Just got the answer from a forum member. Thanks for the help folks and pointing me in the correct direction.

laughingcamera:
Very new to all this. I really only want to learn how to do this to complete a project I have designed, do not want to become a coder, so please go easy on me.

No problem, this is perfectly fine. You should take this to the "Gigs and Collaborations" subforum, because that's the correct place for it.

Trying to get this code to start the loop one time with the push of a button. And if the button is not pushed, I want nothing to happen. Can not get it to do it. I know I am probably missing something very obvious to the forum.

I have looked at your code, and as far as I can see is would do exactly what you have said: it sits there doing nothing, and when you push the button it begins going through its routine.

I suspect that you need to more carefully define what you want the sketch to do. Are you saying that it should only be firing while the button is being held down? IS the sketch only ever going to take one seris of photos, and then never do anything at all unless you power down or reset the board? I'm also a bit puzzled by the three second delay on the camera fire pin: does your camera really take an entire three seconds to take a photo?

Go to G&C, and expect some detailed questions about what, exactly, you would like your sketch to do.