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.
Actuator/Servo.cpp
- Committer:
- yeongsookim
- Date:
- 2019-11-11
- Revision:
- 0:b638163ed537
File content as of revision 0:b638163ed537:
#include "Servo.h"
Servo::Servo(PinName IN): m_PWM(IN)
{
m_degree=0;
m_width= MID+(0.0005/90.0)*m_degree;
m_period_ticker.attach(callback(this, &Servo::setPeriod),0.02);
m_width_timeout.attach(callback(this, &Servo::setWidth),m_width);
m_PWM=1;
}
void Servo::setWidth()
{
m_PWM=0;
}
void Servo::setPeriod()
{
m_width_timeout.attach(callback(this, &Servo::setWidth),m_width);
m_PWM=1;
}
float Servo::getDegree()
{
return m_degree;
}
void Servo::update(float degree)
{
if(degree>MAX) {
degree=MAX;
}
if(degree<-1*MAX) {
degree=MAX*-1;
}
m_degree=degree;
m_width= MID+(0.0005/90.0)*degree;
}