simplify for single SG90
Fork of SG90 by
SG90.cpp@1:93e46a70966f, 2018-06-18 (annotated)
- Committer:
- oldmon
- Date:
- Mon Jun 18 12:02:48 2018 +0000
- Revision:
- 1:93e46a70966f
- Parent:
- 0:a62b163b1dbb
SG90 simpllfy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iLyngklip | 0:a62b163b1dbb | 1 | #include "SG90.h" |
iLyngklip | 0:a62b163b1dbb | 2 | |
oldmon | 1:93e46a70966f | 3 | SG90::SG90(PinName pwmPin):PwmOut(pwmPin){ |
oldmon | 1:93e46a70966f | 4 | iPreRotate=1450; |
oldmon | 1:93e46a70966f | 5 | period_ms(20);// 50Hz to trigger SG90 |
oldmon | 1:93e46a70966f | 6 | pulsewidth_us(iPreRotate); //500:90 1450:0 2400:-90 |
oldmon | 1:93e46a70966f | 7 | } |
oldmon | 1:93e46a70966f | 8 | void SG90::SetAngle(float fAngle){ |
oldmon | 1:93e46a70966f | 9 | if (fAngle>90.0f) |
oldmon | 1:93e46a70966f | 10 | fAngle=90.0f; |
oldmon | 1:93e46a70966f | 11 | else if(fAngle<-90.0f) |
oldmon | 1:93e46a70966f | 12 | fAngle=-90.0f; |
oldmon | 1:93e46a70966f | 13 | int iRotate=(-(fAngle-90.0f)*950.0f/90.0f)+500.0f; |
oldmon | 1:93e46a70966f | 14 | pulsewidth_us(iRotate); |
oldmon | 1:93e46a70966f | 15 | } |