Go Down

Topic: PWM Output (Read 757 times) previous topic - next topic

terminatueur7650

Hello everybody, i try to rotate a servo but i dont know where are my pwm output so i try on the A0 analogig input:



http://image.noelshack.com/fichiers/2015/52/1450805492-20151031-153503.jpg


Code: [Select]
#include <Servo.h>
#define INCR  1
// on déclare le servomoteur comme une variable typée
Servo servo1;
// l'angle actuel du servomoteur
int angle = 0;
// le sens actuel du servomoteur
int sens = 0;
/**
 * Initialisation du programme
 */
void setup()
{
  servo1.attach(0); // le servomoteur est sur une patte PWM
}
/**
 * Boucle infinie qui va gérer la rotation et faire alterner le sens de rotation
 */
void loop()
{
    // faire tourner le servomoteur
    if (sens == 0)
    {
      angle += INCR;
    }
    else {
      angle -= INCR;
    }
    // si on est arrivé à une extremité
    if (angle == 0)
    {
      sens = 0;
    }
    if (angle == 180) {
      sens = 1;
    }
    delay(10);
    servo1.write(angle);
}



And i have launch the code for turn the servo but nothing work servo dont turn... and i dont know in the code if its the good pin for the line
Code: [Select]
servo1.attach(0);


If you have the answer plz help me, sorry for my bad english.

Delta_G

If you have the servo connected to analog pin 0 then this should be:

Code: [Select]
servo1.attach(A0);
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

terminatueur7650

Sorry my problem is resolved it's was not connect on the good pin.... i need to connect it to the digital and not on the analog.

Delta_G

No, you can use one of the analog pins for a servo as long as you use the right numbers.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

terminatueur7650

Okai so i think its was not the right number

Paul__B

"Analog" pins on the Arduino (with very few particular exceptions) are actually standard digital pins to be read and written as any others, but which also happen to be inputs to the analog multiplexer.

Now note also that whilst servo control signals are a particular form of "PWM", they are not the sort of PWM generated by the hardware available on certain pins but instead by a piece of code which therefore can be configured to control any digital pin.

Go Up