For my robot I am using both servo library and the virtual wire library. I was trying to figure out a way to use both and I downloaded servotimer2. I downloaded it and tried to play with the same numbers I use for the normal servo library. I even used something to help convert pwm to degrees so it would work. I played with my servos and had to center them to make them run correctly, but after that I figured out an error that was occuring; my robot just did a continuous circle. With the servo timer2 library I used the same degrees I used in the normal library. Anything I can do to fix this because I have to use the virtualwire library and some library that helps me move the servos.
Here is the servotimer2 code that causes the dog chasing it's tail in a circle.
#include <ServoTimer2.h> // the servo library
// defined the pins for the servos
#define leftWpin 10
#define rightWpin 12
const int MIN_PULSE = 544; // the shortest pulse sent to a servo (0 degrees)
const int MAX_PULSE = 2400; // the longest pulse sent to a servo (180 degrees)
int degreesToUS(int degrees)
{
return (map,degrees, 0,180, MIN_PULSE, MAX_PULSE);
}
ServoTimer2 leftWheel; // declare variables for up to eight servos
ServoTimer2 rightWheel;
void setup() {
leftWheel.attach(rightWpin); // attach a pin to the servos and they will start pulsing
rightWheel.attach(leftWpin);
leftWheel.write(degreesToUS(50));
rightWheel.write(degreesToUS(130));
delay(950);
rightWheel.detach();
leftWheel.detach();
}
void loop()
{
}
The normal servo library that makes the robot go straight.
#include <Servo.h> // Include servo library
Servo servoRight; // Declare right servo
Servo servoLeft;
void setup() // Built in initialization block
{
servoRight.attach(12); // Attach right signal to pin 12
servoLeft.attach(10);
servoLeft.write(50); // Left wheel clockwise
servoRight.write(130); // Right wheel counterclockwise
}
void loop() // Main loop auto-repeats
{
}
Please any help with be much appreciated.