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.
Dependents: serial_connected_mcu_nucleo serial_connected_mcu_nucleo
Diff: servo.cpp
- Revision:
- 0:54b8292756b8
- Child:
- 1:ffc003a37375
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/servo.cpp Fri Feb 26 16:09:01 2016 +0000
@@ -0,0 +1,17 @@
+#include "servo.hpp"
+#include "mbed.h"
+
+namespace mbed_stl {
+
+const float servo::min_position_sec_ = 0.9f * 0.001f;
+const float servo::max_position_sec_ = 2.1f * 0.001f;
+
+servo::servo(PinName pin) : pwm_(pin) {
+ pwm_.period(20.0f * 0.001f);
+}
+
+void servo::set_position(float pos) {
+ pwm.pulsewidth((1.0f - pos) * min_position_sec + pos * max_position_sec);
+}
+
+} /* namespace mbed_stl */