Hello,
I have a NIKKO electronic car that I want to control with an Arduino 3 wires are for the potentiometer and 2 for motor and 1 to avoid 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 sometimes 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); // initialise la connexion
pinMode(GAUCHE, OUTPUT);
pinMode(DROIT, OUTPUT);
digitalWrite(DROIT,LOW);
digitalWrite(GAUCHE,LOW); // evite les cours circuit et l'utilisation de la batterie
pinMode(INFO, INPUT);
}
void loop() {
setAngle(135);
delay(500);
setAngle(65);
delay(500);
}
void setAngle(int angle){
int position_servo=analogRead(INFO); // Make the potentiometer's position into an angle
 int old_angle=map(position_servo,190,800,30,150);
 if(angle-old_angle<0){
   //which means the actual position of the motor is superior to the one i want to go
 analogWrite(GAUCHE, VITESSE_FONCTIONNEMENT_SERVO); // he must go left so i power one the one which help him to go left
 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);
 digitalWrite(GAUCHE,LOW);
 }
Â
Â
 else if (angle-old_angle>0){
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
Thank you