I am new to circuitry and the Arduino. I am attaching a picture of my set up. I bought the basic starter kit and I am trying to combine the Servo control from the "Mood Cue" project and the variable motor control from the "Zeotrope" project.
So I can run the motor if I remove all the Servo code from the program and I can run the servo if I remove all the motor control code. but when I try to write to the Servo in the following code neither the servo or the motor runs correctly. Any help would be greatly appreciated.
Code:
#include <Servo.h>
Servo myServo; // create a servo object
//Constants for the Motor via H-Bridge
const int controlPin1 = 2; // connected to pin 7 on the H-bridge
const int controlPin2 = 3; // connected to pin 2 on the H-bridge
const int enablePin = 10; // connected to pin 1 on the H-bridge
//Variable for the Servo
//int angle; // variable to hold the angle for the servo motor
void setup() {
myServo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
// Put the enable pin LOW to start
digitalWrite(enablePin, LOW);
}
void loop() {
//myServo.write(90); //If this line is commented the motor works, otherwise the motor does not run.
delay(15);
digitalWrite(controlPin1, HIGH); //motor forward
digitalWrite(controlPin2, LOW);
analogWrite(enablePin, 125); //motor half power
delay(3000); //motor runs for 3 seconds
analogWrite(enablePin, 0); //stop the motor
delay(3000); //pause 3 seconds
//myServo.write(60);
delay(15);
digitalWrite(controlPin1, LOW); //reverse motor
digitalWrite(controlPin2, HIGH);
analogWrite(9, 125); //motor half power
delay(3000); //motor runs for 3 seconds
analogWrite(enablePin, 0); //stop the motor
delay(3000); //pause 3 seconds
}