In isolation (73 years old) and trying to get my macro photo stacking rail to return to start without a limit switch. I know the number of steps taken, so it is just a matter of reversing the motor. My code (copied and pasted from other sites) works like a dream (10 steps, fire an IR camera trigger) and continues up to when I want to return (line 73) taking 100 shots or steps however many I want - no problem.
I started a void return loop (and terminated the loop) but the coding has me beat. I have attached my code (might look terrible, but it works). Can anyone help out this old guy and give me the code to counter clockwise 1000 steps?
Thanks fellas David
[code]
#include <AccelStepper.h>
#include <MultiStepper.h>
int smDirectionPin = 2; //Direction pin
int smStepPin = 3; //Stepper pin
int Distance = 0; // records the number of steps we have taken
byte numRepeats = 0;
byte maxRepeats = 100;
int smFirePin = 13; //Trigger pin
#define fire 13
void setup(){
/*Sets all pin to output; the microcontroller will send them(the pins) bits, it will not expect to receive any bits from thiese pins.*/
pinMode(2, OUTPUT); //Direction Pin
pinMode(3, OUTPUT); //Step Pin
pinMode(13, OUTPUT); //LED pin
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(13,LOW);
pinMode(smDirectionPin, OUTPUT);
pinMode(smStepPin, OUTPUT);
Serial.begin(9600); //Open Serial connection for debugging
}
void loop(){
if (numRepeats < maxRepeats) {
move1Step();
Distance = Distance + 1; //record this step to see if we are et the end of our move
if (Distance == 10)
{
if (digitalRead(2) == LOW)
{
digitalWrite(2 , LOW);
}
else
{
digitalWrite(2, LOW);
}
Distance = 0;
numRepeats ++;
delay(3000);
{
trigger();
}
}
}
}
void move1Step() {
digitalWrite(3, HIGH);
delayMicroseconds(750);
digitalWrite(3, LOW);
delayMicroseconds(750);
}
// Power on the IR trigger circuit to fire the camera
void trigger()
{
delay(1000); // wait for vibration to settle
digitalWrite(fire, HIGH); // take the picture
delay(2000); // wait for that to happen
digitalWrite(fire, LOW); // disable the IR circuit again
}
// Advance the motor by one step
void step()
{
digitalWrite(step, HIGH); //Trigger one step forward
delay(1);
digitalWrite(step, LOW); //Pull step pin low so it can be triggered again
delay(1);
}
void return();
{
digitalWrite(smDirectionPin, HIGH);
/*Slowly turns the motor 1600 steps*/
for (int i = 0; i <200; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(700);
digitalWrite(smStepPin, LOW);
delayMicroseconds(700);
}
while(1) { }
}
[/code]
if (digitalRead(2) == LOW) { digitalWrite(2 , LOW); } else { digitalWrite(2, LOW); }
... that whole block can be replaced bydigitalWrite(2, LOW);
return
is a reserved word, so you should rename the function to, for example,returnHome
. You also need to remove the;
at the end of that line of code.