9 years, 3 months ago.

What is a servo following code and what are its prefixes ?

  1. include "mbed.h"

AnalogIn position(A0); PwmOut servo(D3);

int main() { servo requires a 20ms period servo.period(0.020f); while (1) { servo position determined by a pulse width between 1-2ms servo.pulsewidth(0.001f + 0.001f * position); } }

Question relating to:

1 Answer

9 years, 3 months ago.

I assume you are referring to this:

Control a R/C servo with an analog input

#include "mbed.h"
 
AnalogIn position(A0);
PwmOut servo(D3);
 
int main() {
    // servo requires a 20ms period    
    servo.period(0.020f);
    while (1) {
        // servo position determined by a pulse width between 1-2ms
        servo.pulsewidth(0.001f + 0.001f * position);
    }
}

The AnalogIn voltage (on pin A0) will control the position of the servo arm, If standard convention 0 - 3.3v range then 0v should be one end of the servo arm position with 3.3v the other end, that should give you full 'swing' of the servo arm.

So by changing the voltage on pin A0, the servo arm will move accordingly.

Pin D3 will be connected to the servo signal connection (the white wire on the servo).