simplify for single SG90

Dependents:   lidarproj

Fork of SG90 by Mathias Lyngklip

SG90.cpp

Committer:
oldmon
Date:
2018-06-18
Revision:
1:93e46a70966f
Parent:
0:a62b163b1dbb

File content as of revision 1:93e46a70966f:

#include "SG90.h"

SG90::SG90(PinName pwmPin):PwmOut(pwmPin){
    iPreRotate=1450;
    period_ms(20);// 50Hz to trigger SG90
    pulsewidth_us(iPreRotate); //500:90 1450:0 2400:-90   
}
void SG90::SetAngle(float fAngle){
    if (fAngle>90.0f)
        fAngle=90.0f;
    else if(fAngle<-90.0f)
        fAngle=-90.0f;
    int iRotate=(-(fAngle-90.0f)*950.0f/90.0f)+500.0f;
    pulsewidth_us(iRotate);
}