This program is running cw and servo but ccw is not running.
//L293D motor driver
#include <Servo.h>
// Motor A connections
#define enA 9
#define in1 8
#define in2 7
Servo Myservo;
int pos;
void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
Myservo.attach(3);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
delay(100);
digitalWrite(in2, LOW);
delay(100);
}
void loop(){
CW();
servo();
CCW();
exit(0);
}
// This function lets you control spinning direction of motors
void CW() {
// Set motors to maximum speed
analogWrite(enA, 255);
// Turn on motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(5000);
// Turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(1000);
}
void servo(){
for(pos=0;pos=180;pos++){
Myservo.write(pos);
delay(15);
}
}
void CCW(){
// Now change motor directions
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(5000);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(1000);
}
@arukali
Installation and Troubleshooting is for Problems with the Arduino IDE itself NOT your project. It says so in the description of the section. Therefore I have moved your post here. Please be more careful where you post in future.
Side note: you shouldn't be powering the motor and / or servo from the Arduino 5V pin. You should use an external supply; you may be overloading the Arduino's voltage regulator.
On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins