Delays not working/sets of code in loop are skiped

So I wrote my first code and it moves a stepper motor which moves a servo motor to various points with certain delays. The codes seems to skip the third tap in as well as a few delays. I did some googling on why this would be but found nothing. Any help would be greatly appreciated.

//www.elegoo.com
//2016.06.13
//
#include <Servo.h>
#include <Stepper.h>
/
/
Servo myservo;//create servo object to control a servo
//
const int meow = 100;
Stepper myStepper(meow, 8, 10, 9, 11);
/
/
void setup()
{
myservo.attach(12);//attachs the servo on pin 13 to servo object
myservo.write(150);//back to 0 degrees
delay(1000);//wait for a second
/
/
// set the speed at 60 rpm:
myStepper.setSpeed(30);
// initialize the serial port:
Serial.begin(9600);
}
/
*/
void loop()
{

/W4/
delay(1000);

/T2/
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

/T2/
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

/W8/
delay(1000);

/T2/
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

/M1/
Serial.println("clockwise"); //Go to
myStepper.step(-200); //Auto Battle

/W7/
delay(1000);

/T1/
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

/M3/
Serial.println("clockwise"); //Go to
myStepper.step(300); //Confirm Auto

/T3/
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

/M2/
Serial.println("clockwise"); //Go to
myStepper.step(-100); //start

/W9/
delay(1000);

/T2/
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

delay(9000);
/*
myservo.write(110); //Tap
myservo.write(90); //T
delay(350); //a
myservo.write(110); //p

Serial.println("clockwise"); //go to autobattle
myStepper.step(-two2one);
delay(5000);

Serial.println("clockwise"); //go to autobattle
myStepper.step(stepsPerRevolution);
delay(5000);

myservo.write(110); //degrees
delay(3000); //wait
myservo.write(90); //goes to 30 degrees
delay(350); //wait for a second.33
myservo.write(110); //degrees
delay(3000);

Serial.println("counterclockwise"); //go to autobattle
myStepper.step(-stepsPerRevolution);
delay(5000);
*/

}
/**************************************************/

TheDevice.ino (3.13 KB)

You have used Serial.print() for a WHOLE bunch of stuff. Why not use it to show EACH step in your code and the values in the variables used in each step? Then you can easily figure out the errors.

Paul

I hope you aren't powering your stepper motor from the Arduino.

ieee488:
I hope you aren't powering your stepper motor from the Arduino.

I hope so too :sweat_smile: :sweat_smile: :sweat_smile:

Also SpiritKitty put your code into the code brackets it is a mess!

jball:
I hope so too :sweat_smile: :sweat_smile: :sweat_smile:

Also SpiritKitty put your code into the code brackets it is a mess!

don't worry I have them hooked up to a power supply module.

Also what do you mean brackets?

Paul_KD7HB:
You have used Serial.print() for a WHOLE bunch of stuff. Why not use it to show EACH step in your code and the values in the variables used in each step? Then you can easily figure out the errors.

Paul

I'm not exactly sure what you mean by use serial print to show each step. Do you mean put each line(function?) inside "Serial.print()" ?

Paul_KD7HB:
You have used Serial.print() for a WHOLE bunch of stuff. Why not use it to show EACH step in your code and the values in the variables used in each step? Then you can easily figure out the errors.

Paul

I think I know what you meant. I put a serial.print() in between each line and I found my issue I needed a delay between the first two taps it works now. Thank you for the help. :slight_smile: (now the codes even longer)

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

...R

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

​Thanks... Tom... :)

Because your sequence uses lengthy delays between actions, you may benefit from a STATE MACHINE to maintain clear control of the steps.

Equally, you may find some benefit in rationalising the repeating blocks of code into functions.

These two options will make your code much more readable and logical - and probably smaller!