File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ class ServoImpl {
77 mbed::DigitalOut *pin;
88 mbed::Timeout timeout; // calls a callback once when a timeout expires
99 mbed::Ticker ticker; // calls a callback repeatedly with a timeout
10- uint32_t duration;
1110
1211public:
1312 ServoImpl (PinName _pin) {
@@ -34,9 +33,7 @@ class ServoImpl {
3433 *pin = !*pin;
3534 }
3635
37- uint32_t read () {
38- return duration;
39- }
36+ int32_t duration = -1 ;
4037};
4138
4239static ServoImpl* servos[MAX_SERVOS]; // static array of servo structures
@@ -107,7 +104,10 @@ void Servo::writeMicroseconds(int value)
107104 value = SERVO_MAX ();
108105
109106 value = value - TRIM_DURATION;
110- servos[this ->servoIndex ]->start (value);
107+ if (servos[this ->servoIndex ]->duration == -1 ) {
108+ servos[this ->servoIndex ]->start (value);
109+ }
110+ servos[this ->servoIndex ]->duration = value;
111111 }
112112}
113113
@@ -121,7 +121,7 @@ int Servo::readMicroseconds()
121121 if (!servos[this ->servoIndex ]) {
122122 return 0 ;
123123 }
124- return servos[this ->servoIndex ]->read () ;
124+ return servos[this ->servoIndex ]->duration ;
125125}
126126
127127bool Servo::attached ()
You can’t perform that action at this time.
0 commit comments