simplify for single SG90

Dependents:   lidarproj

Fork of SG90 by Mathias Lyngklip

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SG90.cpp Source File

SG90.cpp

00001 #include "SG90.h"
00002 
00003 SG90::SG90(PinName pwmPin):PwmOut(pwmPin){
00004     iPreRotate=1450;
00005     period_ms(20);// 50Hz to trigger SG90
00006     pulsewidth_us(iPreRotate); //500:90 1450:0 2400:-90   
00007 }
00008 void SG90::SetAngle(float fAngle){
00009     if (fAngle>90.0f)
00010         fAngle=90.0f;
00011     else if(fAngle<-90.0f)
00012         fAngle=-90.0f;
00013     int iRotate=(-(fAngle-90.0f)*950.0f/90.0f)+500.0f;
00014     pulsewidth_us(iRotate);
00015 }