12 identical commands with stepper motor distance troubles

I have 12 of these "voids" that are exactly the same, (void sent1 through void sent12 with different steps) but my stepper motor moves to a spot then moves back to a starting location. There is an LED blinking, a servo movement in between the two step amounts and a sound that plays when this happens. I am in need of some code space(almost full) and I think that if I can make this part shorter than I can get the little bit of space that I need to finish my project.

void sent1(){ sent.play("Sent1.wav"); delay(3000); Steps2Take = -70; {sentgo();} {servo();} Steps2Take = 80; {sentback();}} void sent2(){ sent.play("Sent2.wav"); delay(2000); Steps2Take = -240; {sentgo();} {servo();} Steps2Take = 250; {sentback();}} void sent3(){ sent.play("Sent3.wav"); delay(1000); Steps2Take = -400; {sentgo();} {servo();} Steps2Take = 410; {sentback();}} void sent4(){ sent.play("Sent4.wav"); delay(1000); Steps2Take = -580; {sentgo();} {servo();} Steps2Take = 590; {scentback();}}

ANY HELP would be great so I can finish my code. Thanks everyone. :-)

I have 12 of these "voids" that are exactly the same

{sigh} You have twelve functions

What you don't have is CODE TAGS

I'm not sure what you mean by CODE TAGS. The stepper motor has a starting location that is just a stopping point that it bumps into. From that point the stepper motor moves to 12 different spots. Each one of these voids brings the stepper motor to a position and bring the stepper motor back slightly more so it bumps into the stopping point to create the same starting point. I am trying to write the code that will let me have Only one void instead of 12 that I can just change the stepper motor distance then add 10 steps for the return location to bump into the stopping point.

So if CODE TAGS will help me with this, then I would really appreciate your help.

Thanks.

If you stop calling functions "voids", and post your code (all of it) in code tags, I'm sure help will be forthcoming.

LOL!!!! Ok, that is good to know. Thanks for letting me know about code tags. If anyone else can help with this code issue, would be wonderful. Thanks.

void sent1(){
   sent.play("Sent1.wav");
   delay(3000);
   Steps2Take  = -70;
   {sentgo();}
   {servo();}
   Steps2Take  = 80;
   {sentback();}}
void sent2(){
   sent.play("Sent2.wav");
   delay(2000);
   Steps2Take  = -240;
   {sentgo();}
   {servo();}
   Steps2Take  = 250;
   {sentback();}}
void sent3(){
   sent.play("Sent3.wav");
   delay(1000);
   Steps2Take  = -400;
   {sentgo();}
   {servo();}
   Steps2Take  = 410;
   {sentback();}}
void sent4(){
   sent.play("Sent4.wav");
   delay(1000);
   Steps2Take  = -580;
   {sentgo();}
   {servo();}
   Steps2Take  = 590;
   {scentback();}}

No, I wrote "all of it"

I just got to work so I can't post my whole code right now. (didn't bring it with me)

Is there some direction that someone could point me so I can research some possibilities to my dilemma. This way I can learn about the code and not have someone write it 4 me....

Thanks 4 any help that someone can give me. :confused:

You could start researching the use of function arguments/parameters, possibly even the use of sprintf to create filenames.

A look at the blink without delay example might indicate a way of getting rid of calls to the delay function.

Can you post a basic sample to show because I am much better at learning and researching with visuals. :o

And thanks, your are great. :)

I will try to post the whole code later today when I'm off work.

void sent1()
{
   sent.play("Sent1.wav");
   delay(3000);
   Steps2Take  = -70;
   sentgo();
   servo();
   Steps2Take  = 80;
   sentback();
}

// becomes

void sent (char* filename, int delayVal, int steps)
{
   sent.play(filename);
   delay(delayVal);
   Steps2Take  = -steps;
   sentgo();
   servo();
   Steps2Take  = steps + 10;
   sentback();
}

Without seeing the rest of the code, it isn't possible to eliminate delay().

The delay is actually in there because when I use my Servo, it will cut my sound off. I think there is a conflict with the libraries or something. So I just put a delay in and attach/detach my servo only when I use the servo in between the two stepper motor distances.

Thanks soo much 4 the sample.... I should have this researched by the time I get home from work. :sweat_smile:

These are the items that I am using. Just in case you were curious.

arduino nano.jpg

sd card.jpg

micro servo.jpg

Why not have one function and store the different values in two arrays? Pass an number (0-11) to the function so it knows which element of the array to use.

...R