Big Easy driver V4.2 code problems

Greetings all!

Advance notice - I am reasonably new to the arduino, loving
it…learning it… but getting caught out on a few bits

I was wondering if some one could help me with my code to improve my
understanding / usage of the ‘big easy driver’
i understand and have the basics of moving the motor back and forth
and certain number of steps but my end project would be to use this to
create a time lapse rig so im having trouble getting the motor to move
in intervals of ‘x’ amount of steps and stop/change direction when
reaching a total of ‘y’ amout of steps. Meaning im having trouble
working out and including a process to count the steps taken to then
stop/change direction when reach the limit. Am i better off using
‘Return value;’ ‘interupt;’ or creating a seperate vairable
all together?
and then how to include that in to the code with out disturbing the current sketch?

Below is the code i have worked out so far to move in intervals of
‘xyz’, pause, trigger my camera, pause, and then continue to move but
i cant put a limit on it and it goes on forever :frowning:

Any help would be very much appreciated
i thank you for your time!

int dir = 3;
int stepp = 12;
int cam = 10;

void setup () {
Serial.begin(9600);

pinMode(dir, OUTPUT); // set dir pin
pinMode(stepp, OUTPUT); // set step pin
pinMode(cam, OUTPUT); // set camera trigger pin
}

void loop ()
{

int i;

digitalWrite(dir, LOW); // set direction
delay(100); // delay
Serial.println(i); // start print

for (i=0; i<3200; i++) // step loop
{

digitalWrite(stepp, LOW); //
digitalWrite(stepp, HIGH); // step pulse
delayMicroseconds(200); //
}
delay(1000);
digitalWrite(cam, HIGH); // open shutter
delay(2000); // 2 second exposure
digitalWrite(cam, LOW); // close shutter
delay(1000);

}

im having trouble getting the motor to move in intervals of 'x' amount of steps and stop/change direction when reaching a total of 'y' amout of steps. Meaning im having trouble working out and including a process to count the steps taken to then stop/change direction when reach the limit.

Your loop index (i) is, at any point in the loop, the number of steps taken. Each time you step, you need to increment or decrement a counter.

Am i better off using 'Return value;' 'interupt;' or creating a seperate vairable all together?

What return value? Nothing is returning a value.

If you can explain what will be doing the interrupting, and what will happen when the code in loop() is interrupted, interrupts might be a possibility. Very unlikely, but maybe.

That leaves using a separate variable to count the number of steps taken. Nearly trivial to increment or decrement as a forward or reverse step is taken.

Hi PaulS Thanks for your reply, The problem I'm having is :- Trying to get the motor to move in intervals of 3200 micro steps and then fire my camera ( which i have so far ) BUT STOP EVERYTHING at a maximum of say 100,000 steps ( 100,000 = the length of the rail the camera is moving along) So what code can i use to 'keep count' of the total steps done and when the limmit is reached....stop / invert direction ect.. because currently (i) resets to zero at the beginning of the loop thus no help for a 'total' value Im guessing an 'if ... else' would do the job but reading which value?.. (i)?.... or create a seperate 'int' e.g. (x) to keep cout of the total? Sorry if im missing something very simple here or not explaining my self clearly. Your help is very much appreciated.

So what code can i use to ‘keep count’ of the total steps done

A global variable, totalSteps, initialized to 0, incremented every time the motor steps forward, and decremented every time the motor steps backward.