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: ServomotorTests NerfUSTarget
Servomotor.cpp
00001 #include "Servomotor.hpp" 00002 00003 Servomotor::Servomotor(PwmOutInterface &pwm_out) : 00004 up_angle(90), 00005 pwm_out(pwm_out) 00006 { 00007 00008 } 00009 00010 //Angle 0 degree = duty cycle 500 ns 00011 //Angle 90 degree = duty cycle 1500 ns 00012 //Angle 180 degree = duty cycle 2500 ns 00013 void Servomotor::set_angle(const float angle_degree) 00014 { 00015 const float duty_cycle_us = (angle_degree / 180.0) * 2000 + 500; 00016 pwm_out.pulsewidth_us(duty_cycle_us); 00017 } 00018 00019 void Servomotor::set_position_up() 00020 { 00021 set_angle(up_angle); 00022 } 00023 00024 void Servomotor::set_position_down() 00025 { 00026 set_angle(up_angle - 90); 00027 }
Generated on Thu Jul 14 2022 19:16:36 by
