File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -376,16 +376,24 @@ void Servo::detachAll() {
376376
377377void Servo::write (int value)
378378{
379- if (value < 0 )
379+ float tempValue;
380+
381+ if (value <= 0 )
382+ {
383+ tempValue = 0.0 ;
384+ }
385+ else if (value >= 180 )
380386 {
381- value = 0 ;
387+ tempValue = 180. 0 ;
382388 }
383- else if (value > 180 )
389+ else
384390 {
385- value = 180 ;
391+ tempValue = ( float )value ;
386392 }
387- value = (((this ->max - this ->min ) * value) / 180 ) + this ->min ;
388393
394+ tempValue = (((this ->max - this ->min ) * tempValue) / 180.0 ) + this ->min ;
395+
396+ value = (int )tempValue;
389397 this ->writeMicroseconds (value);
390398}
391399
@@ -427,7 +435,6 @@ void Servo::writeMicroseconds(int value)
427435 }
428436}
429437
430-
431438int Servo::read () {
432439 float angle;
433440
You can’t perform that action at this time.
0 commit comments