I'm working on the RC car project that uses both servo and 433HZ wireless control. What I noticed and learned from the internet is that both Servo.h and virtualwire.h libraries use the same timer which is the timer1. So I switched the Servo.h to a new library called ServoTimer2. To test if this new library work, I used it in a simple joystick control project but it doesn't work. Here is my code of the joystick code:
#include <ServoTimer2.h>
ServoTimer2 myServo;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
pinMode(10, OUTPUT);
myServo.attach(9);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(200);
\
if(analogRead(X_pin) < 400)
{
myServo.write(25);
delay(20);
}
if(analogRead(X_pin) > 600)
{
myServo.write(155);
delay(20);
}
if(analogRead(Y_pin) > 750)
{
digitalWrite(10, HIGH);
}
if(analogRead(Y_pin) < 750)
digitalWrite(10, LOW);
if(analogRead(X_pin) > 450 && analogRead(X_pin) < 650 )
{
myServo.write(90);
delay(20);
}
}