Hello,
I have a NIKKO electronic car that I want to control with an Arduino I know that 3 wires are for the potentiometer and 2 for motor and 1 for the parasites.
But when i created my function to go to a specific angle I encounter problems : it just turn in one way without stopping and sometime it doesn't work at all
Here is my code
int const INFO = A0;
int const GAUCHE = 5;
int const DROIT = 6;
int const VITESSE_FONCTIONNEMENT_SERVO = 100;
int position_servo;
int old_val = -1;
int potar=0;
void setup() {
 // put your setup code here, to run once:
Serial.begin (9600);
pinMode(GAUCHE, OUTPUT);
pinMode(DROIT, OUTPUT);
digitalWrite(DROIT,LOW);
digitalWrite(GAUCHE,LOW); // avoid short circuit
pinMode(INFO, INPUT);
}
void loop() {
setAngle(135);
delay(500);
setAngle(65);
delay(500);
}
void setAngle(int angle){
int position_servo=analogRead(INFO); // read the potentiometer's value
 int old_angle=map(position_servo,190,800,30,150);// make it correpond to an angle
 if(angle-old_angle<0){
   //must reach a position which is to the left of his actual position
 analogWrite(GAUCHE, VITESSE_FONCTIONNEMENT_SERVO);Â
 digitalWrite(DROIT, LOW);
 do {
   Â
  int position_servo=analogRead(INFO);
  int old_angle=map(position_servo,190,800,30,150);
  delay(1);
 }while(old_angle>angle); // powers the "left" wire until he gets to the right postion
 digitalWrite(GAUCHE,LOW);
 }
Â
Â
 else if (angle-old_angle>0){ // if angle i want is inferior to the one it is acutally at
digitalWrite(GAUCHE, LOW);Â
 analogWrite(DROIT, VITESSE_FONCTIONNEMENT_SERVO);
  do {
  Â
  int position_servo=analogRead(INFO);
  int old_angle=map(position_servo,190,800,30,150);
  delay(1);
 }while(old_angle < angle);
 digitalWrite(DROIT,LOW); Â
}
}
I don't understand why he doesn't work (it doesn't come from the wire because i can make the motor move) English is not my mother language but i did my best to explain clearly my problem
Please help me it's for a project if you have any question I'll be glad to answer them(must I say it or them ?)
Thank you