Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Actionneurs/Servo.cpp
- Revision:
- 0:1cfd66c3a181
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Actionneurs/Servo.cpp Wed May 22 16:54:27 2019 +0000 @@ -0,0 +1,33 @@ +#include "Servo.h" +#include "mbed.h" + +// Constructeur: +Servo::Servo(PinName pin) : m_pin(pin) {} + +// Active le servomoteur: +void Servo::enable(int startPos, float period) { + m_position = startPos; + m_pulse.attach_us(callback(this, &Servo::startPulse), period); +} + +// Désactive le servomoteur: +void Servo::disable() { + m_pulse.detach(); +} + +// Déplace le servomoteur à la position angle (en °): +void Servo::pos(int angle) { + // Conversion degrée en durée d'impulsion: + m_position = -11.111f * angle + 2500; +} + +// Début d'une impulsion: +void Servo::startPulse() { + m_pin = 1; + m_pulseStop.attach_us(callback(this, &Servo::endPulse), m_position); +} + +// Fin de l'impulsion: +void Servo::endPulse() { + m_pin = 0; +}