I´m constructing a Time lapse rigg where a platform is traveling on a rail of approx. 1,5m/4,92ft. The platform is motorized by a stepper motor and controlled by a Motor Shield Kit v1.1 from Adafruit on top of an Arduino UNO.
The problem is that i´m fairly new to programming logic and have now got stuck in code...
My stepper can do 200 steps/rev,So to travel the <1,5m/4,92ft> it takes the stepper ~3900 steps
What I want to do is to take 150 pictures in these 3900 steps, which makes one picture every 26 steps.
I have implemented a ´for´ loop and this is where i´m not up to speed... I just don´t have top experience in loop commands. Don´t know where to look for errors.
Its good when I run it through the verifier but when I run the program on the rigg it just skips the 26 steps (plus the adding process) and goes directly to: motor.step(3900, BACKWARD, SINGLE);
The code i´m currently trying to make work is:
[Edit - moderator - use "Code" button when submitting code]
Code: Select all
#include <AFMotor.h>
AF_Stepper motor(200, 2); // 360/1.8 degrees.per.step = 200 steps/rev and If you're using M1 and M2, its port 1. If you're using M3 and M4 its port 2
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps = 1,2Kb/s . This is how fast the connection can read and write bits on the wire.
pinMode(2, OUTPUT);
motor.setSpeed(10); // 10 rpm
}
void loop()
{
int x = 26;
for (int i = 0; i < 3900; i = i+x) // Starts the counter on 0 and adds a "26 step" each loop for 150 times up to 3900, witch is the stop of the line...
{
motor.step(i, FORWARD, SINGLE); // i steps is how many steps you'd like it to take. direction is either FORWARD or BACKWARD and the step type is SINGLE, DOUBLE. INTERLEAVE or MICROSTEP. "Single" means single-coil activation
delay(3000); // Waits 3 sec due to vibrations to set
digitalWrite(2, HIGH); // sends an impulse to the Canon 60D to take an image
delay(1000); // waits for a second
digitalWrite(2, LOW); // turn impulse off
delay(2000);
if(i == 3900);
{
motor.step(3900, BACKWARD, SINGLE);
delay(300000000); // wait for a long time
break; // Exit the loop
}
}
}
Thanks... / Dave