[SOLVED] NOOB order query

Hi, I am pretty much a noob so please be gentle with me!

I am trying to set up a camera slider that moves a camera (Stepper Motor X), pans (Stepper Motor Y) and then focuses and releases the shutter. (Foucus has to be high whilst shutter is on to take a picture)

I am currently using an Uno CNC shield to help with the stepper motor control

I am currently struggling to get everything going in the correct order and I can't figure out why.

Start again.

The code I currently have is below where am I going so wrong?

The sequence I would like would be

Stepper X 200 Steps
Stepper Y 20 Steps
Focus on for 4 secs before
Shutter on 1/2 sec
Shutter off
Focus off

Loop to start. Eventually I will add a microswitch to stop movement at the end of the track but I'll worry about that later!


const int StepX = 2;
const int DirX = 5;
const int StepY = 3;
const int DirY = 6;
const int Shutter = 4;
const int Focus = 7;


void setup() {
  
  pinMode(StepX,OUTPUT);
  pinMode(DirX,OUTPUT);
  pinMode(StepY,OUTPUT);
  pinMode(DirY,OUTPUT);
  pinMode(Shutter,OUTPUT);
  pinMode(Focus,OUTPUT);

}

void loop() {
  

void SliderMotor ();
{
  digitalWrite(DirX, HIGH);
 for(int x = 0; x<200; x++) { // loop for 200 steps
  digitalWrite(StepX,HIGH);
  delayMicroseconds(500);
  digitalWrite(StepX,LOW); 
  delayMicroseconds(500);
  delay(3000);
 }
 // delay for 3 second
void PanMotor ();
{
  digitalWrite(DirY, LOW);
 for(int x = 0; x<20; x++) { // loop for 20 steps
  digitalWrite(StepY,HIGH);
  delayMicroseconds(500);
  digitalWrite(StepY,LOW); 
  delayMicroseconds(500);
  delay(3000);// delay for 3 second
 }


void Shutter();
{
  digitalWrite(Focus,HIGH);//focus camera on
  delayMicroseconds(4000);
  digitalWrite(Shutter, HIGH);//take picture
  delayMicroseconds(500);
  digitalWrite(Shutter,LOW);
  delayMicroseconds(1000);
  digitalWrite(Focus,LOW);
  delayMicroseconds(4000);
 }


}}}

Welcome to the forum

void loop()
{
  void SliderMotor ();
  {
    digitalWrite(DirX, HIGH);
    for (int x = 0; x < 200; x++) // loop for 200 steps
    {

To start with you have a function definition inside a function

1 Like
const int StepX = 2;
const int DirX = 5;
const int StepY = 3;
const int DirY = 6;
const int Shutter = 4;
const int Focus = 7;

void setup()
{
  pinMode(StepX, OUTPUT);
  pinMode(DirX, OUTPUT);
  pinMode(StepY, OUTPUT);
  pinMode(DirY, OUTPUT);
  pinMode(Shutter, OUTPUT);
  pinMode(Focus, OUTPUT);
}

void loop()
{
//  SlideMotor();
//  PanMotor();
//  Shutter();
}

void SliderMotor ()
{
  digitalWrite(DirX, HIGH);
  for (int x = 0; x < 200; x++)   // loop for 200 steps
  {
    digitalWrite(StepX, HIGH);
    delayMicroseconds(500);
    digitalWrite(StepX, LOW);
    delayMicroseconds(500);
    delay(3000); // delay for 3 second
  }
}

void PanMotor ()
{
  digitalWrite(DirY, LOW);
  for (int x = 0; x < 20; x++)   // loop for 20 steps
  {
    digitalWrite(StepY, HIGH);
    delayMicroseconds(500);
    digitalWrite(StepY, LOW);
    delayMicroseconds(500);
    delay(3000); // delay for 3 second
  }
}

void Shutter()
{
  digitalWrite(Focus, HIGH); //focus camera on
  delayMicroseconds(4000);
  digitalWrite(Shutter, HIGH);//take picture
  delayMicroseconds(500);
  digitalWrite(Shutter, LOW);
  delayMicroseconds(1000);
  digitalWrite(Focus, LOW);
  delayMicroseconds(4000);
}

No user functions are called in setup() or loop() so the code does nothing.

Thanks.

This was a last ditch attempt. Maybe need to go back to arduino school.

  void SliderMotor ();

What are you trying to do with this line ?
Are you trying to call the function or to define the function ?

I've tidied it up closer to where I started.

Is this better? Its still not sequencing properly but is less complicated I think

const int StepX = 2;
const int DirX = 5;
const int StepY = 3;
const int DirY = 6;
const int Shutter = 4;
const int Focus = 7;


void setup() {
  pinMode(StepX,OUTPUT);
  pinMode(DirX,OUTPUT);
  pinMode(StepY,OUTPUT);
  pinMode(DirY,OUTPUT);
  pinMode(Shutter,OUTPUT);
  pinMode(Focus,OUTPUT);

}

void loop() {
 digitalWrite(DirX, HIGH); // set direction, HIGH for clockwise, LOW for anticlockwise
 digitalWrite(DirY, HIGH);
 digitalWrite(Focus, HIGH);
 
 for(int x = 0; x<200; x++) { // loop for 200 steps
  digitalWrite(StepX,HIGH);
  delayMicroseconds(500);
  digitalWrite(StepX,LOW); 
  delayMicroseconds(500);
 }
delay(1000); // delay for 1 second

for(int x = 0; x<200; x++) { // loop for 200 steps
  digitalWrite(StepY,HIGH);
  delayMicroseconds(500);
  digitalWrite(StepY,LOW); 
  delayMicroseconds(500);
 }
delay(1000);{ // delay for 1 second

 digitalWrite(Focus,HIGH);//focus camera on
  delayMicroseconds(4000);
  digitalWrite(Shutter, HIGH);//take picture
  delayMicroseconds(1000);
  digitalWrite(Shutter,LOW);
  delayMicroseconds(1000);
  digitalWrite(Focus,LOW);
  delayMicroseconds(4000);
 }
delay(1000); // delay for 1 second

}

DelayMicrroseconds is fine for steppers, but did you really mean to use them for your focus and shutter delays?

1 Like

It compiles so that is a big advance
Whether it does what you want is another matter

1 Like

No, should I just use delay?

Yes.

1 Like

Might just be the problem! Mili vs Micro Doh! Thanks will try that when I get home!

Sorted thanks to the delay issue! Thanks everyone! I’ll be back asking for help with inputs to control the slider motor movement and stop switches next! Thank you all!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.