Dependents: serial_connected_mcu_nucleo serial_connected_mcu_nucleo
Revision 2:58169cf31b49, committed 2016-06-25
- Comitter:
- inst
- Date:
- Sat Jun 25 05:18:53 2016 +0000
- Parent:
- 1:ffc003a37375
- Child:
- 3:6cadf3326257
- Commit message:
- ??????;
Changed in this revision
servo.cpp | Show annotated file Show diff for this revision Revisions of this file |
servo.hpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/servo.cpp Fri Feb 26 16:27:25 2016 +0000 +++ b/servo.cpp Sat Jun 25 05:18:53 2016 +0000 @@ -1,18 +1,13 @@ #include "servo.hpp" -#include "mbed_stl.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; -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); +servo::servo(PinName pin) : _pwm(pin) { + _pwm.period(20.0f * 0.001f); } void servo::set_position(float pos) { - pwm_.pulsewidth(linear_algebra::lerp(pos, min_position_sec_, max_position_sec_)); + _pwm.pulsewidth((1.0f - pos) * _min_position_sec + pos * _max_position_sec); } - -} /* namespace mbed_stl */
--- a/servo.hpp Fri Feb 26 16:27:25 2016 +0000 +++ b/servo.hpp Sat Jun 25 05:18:53 2016 +0000 @@ -3,19 +3,15 @@ #include "mbed.h" -namespace mbed_stl { - class servo{ public: servo(PinName pin); void set_position(float pos); private: - static const float min_position_sec_; - static const float max_position_sec_; - PwmOut pwm_; + static const float _min_position_sec; + static const float _max_position_sec; + PwmOut _pwm; }; -} /* namespace mbed_stl */ - #endif