HI,
I have make a rc car with servo and dc motor . I work it with REMOTEXY(bluetooth) and control with phone.
My problem is that when i get work dc motor and servo don't work.if i test servo differetion to dc motor and up side down they work.
THANKS FOR YOUR TIME.
check my program :
#include <Servo.h>
Servo myservo;
/* defined the right motor control pins */
#define PIN_MOTOR_RIGHT_UP 7
#define PIN_MOTOR_RIGHT_DN 6
#define PIN_MOTOR_RIGHT_SPEED 10
/* defined the left motor control pins */
#define PIN_MOTOR_LEFT_UP 5
#define PIN_MOTOR_LEFT_DN 4
#define PIN_MOTOR_LEFT_SPEED 9
/* defined two arrays with a list of pins for each motor */
unsigned char RightMotor[10]=
{PIN_MOTOR_RIGHT_UP, PIN_MOTOR_RIGHT_DN, PIN_MOTOR_RIGHT_SPEED};
unsigned char LeftMotor[9] =
{PIN_MOTOR_LEFT_DN, PIN_MOTOR_LEFT_UP, PIN_MOTOR_LEFT_SPEED};
void Wheel (unsigned char * motor, int v)
{
//if (v>100) v=100;
//if (v<-100) v=-100;
//if (dist>=60) RemoteXY.slider_1=0;
if (v>0) {
digitalWrite(motor[0], HIGH);
digitalWrite(motor[1], LOW);
analogWrite(motor[2], RemoteXY.slider_1); //v*2.55
}
else if (v<0) {
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], HIGH);
analogWrite(motor[2], RemoteXY.slider_1); //(-v)*2.55
}
else {
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
analogWrite(motor[2], 0);
}
}
void setup()
{
pinMode (PIN_MOTOR_RIGHT_UP, OUTPUT);
pinMode (PIN_MOTOR_RIGHT_DN, OUTPUT);
pinMode (PIN_MOTOR_LEFT_UP, OUTPUT);
pinMode (PIN_MOTOR_LEFT_DN, OUTPUT);
RemoteXY_Init();
Serial.begin(9600);
myservo.attach(3);
}
void loop()
{
RemoteXY_Handler();
if (RemoteXY.switch_1==0) {
RemoteXY.led_1_r = 0;
}
else {
RemoteXY.led_1_r = 255;
int ms = RemoteXY.slider_220+500;
myservo.writeMicroseconds(ms);
Wheel (RightMotor, RemoteXY.joystick_1_y - RemoteXY.joystick_1_x);
/ manage the left motor */
Wheel (LeftMotor, RemoteXY.joystick_1_y + RemoteXY.joystick_1_x);
}
}