Hi There,
I have been making a camera slider for motion timelapse and have come to a hault with some coding. I basically need for the main bit of the code to repeat so many times so the slider goes in one direction (at the moment is it set to do it 10 times, I think) - once that has been completed I would like it to go back to the start in one movement and either start the first bit of code again or stop completely. I have been trying to find some code where it counts every time the step is completed and once the limit has been reached then another piece of code it activated to take the slider to the beginning.
Could someone point me in the right direction?
Cheers,
James
#define RELAY 6 // Pin number 6 on Arduino Board
#define DIRECTION 7 // Pin number 7 on Arduino Board
#define STEP_PIN 8 // Pin number 8 on Arduino Board
int movemotor = 10; // Runs program 10 times
void setup(){
pinMode(RELAY, OUTPUT); // Sets RELAY as an OUTPUT (Pin 6)
pinMode(DIRECTION, OUTPUT); // Sets DIRECTION as an OUTPUT (Pin 7)
pinMode(STEP_PIN, OUTPUT); // Sets STEP_PIN as an OUTPUT (Pin 8)
}
void loop(){
/* 8 microsteps per step. A 200 step stepper would take 1600 micro steps for one full revolution.
.25 is best speed for my motor - 15200 microsteps = 9.5 revolutions of motor (15200 / 1600 = 9.5) */
if (movemotor >=10){
rotate(-1520, .25); // Move so many steps at .25 speed
delay(1000); // Delay to stop camera shake (1 Sec)
digitalWrite(RELAY,HIGH); // Turn RELAY ON (Fires camera)
delay(300); // Delay for 1/30th Sec
digitalWrite(RELAY,LOW); // Turn RELAY OFF
delay(1700); // Delay for 1.7 Sec before continuing
}
}
void rotate(int steps, float speed){
/* rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger */
int dir = (steps > 0)? HIGH:LOW;
steps = abs(steps);
digitalWrite(DIRECTION,dir);
float usDelay = (1/speed) * 70;
for(int i=0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(usDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(usDelay);
}
}