diff --git a/libraries/Servo/src/Servo.h b/libraries/Servo/src/Servo.h index 894d2679a56..168e788c177 100644 --- a/libraries/Servo/src/Servo.h +++ b/libraries/Servo/src/Servo.h @@ -102,7 +102,8 @@ class Servo void writeMicroseconds(int value); // Write pulse width in microseconds int read(); // returns current pulse width as an angle between 0 and 180 degrees int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) - bool attached(); // return true if this servo is attached, otherwise false + bool attached(); // return true if this servo is attached, otherwise false + int getAttachedPin(); // returns the pin the servo is attached to. private: uint8_t servoIndex; // index into the channel data for this servo int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH diff --git a/libraries/Servo/src/avr/Servo.cpp b/libraries/Servo/src/avr/Servo.cpp index 7fdd9d52e35..7589b124343 100644 --- a/libraries/Servo/src/avr/Servo.cpp +++ b/libraries/Servo/src/avr/Servo.cpp @@ -313,5 +313,13 @@ bool Servo::attached() return servos[this->servoIndex].Pin.isActive ; } +int Servo::getAttachedPin() +{ + if (this->servoIndex != INVALID_SERVO) + return servos[this->servoIndex].Pin.nbr; + else + return 0; +} + #endif // ARDUINO_ARCH_AVR diff --git a/libraries/Servo/src/sam/Servo.cpp b/libraries/Servo/src/sam/Servo.cpp index 21f901f0e40..d009fbacd9a 100644 --- a/libraries/Servo/src/sam/Servo.cpp +++ b/libraries/Servo/src/sam/Servo.cpp @@ -279,5 +279,13 @@ bool Servo::attached() return servos[this->servoIndex].Pin.isActive; } +int Servo::getAttachedPin() +{ + if (this->servoIndex != INVALID_SERVO) + return servos[this->servoIndex].Pin.nbr; + else + return 0; +} + #endif // ARDUINO_ARCH_SAM diff --git a/libraries/Servo/src/samd/Servo.cpp b/libraries/Servo/src/samd/Servo.cpp index 42a3877a6d9..10c7be15b65 100644 --- a/libraries/Servo/src/samd/Servo.cpp +++ b/libraries/Servo/src/samd/Servo.cpp @@ -294,4 +294,12 @@ bool Servo::attached() return servos[this->servoIndex].Pin.isActive; } +int Servo::getAttachedPin() +{ + if (this->servoIndex != INVALID_SERVO) + return servos[this->servoIndex].Pin.nbr; + else + return 0; +} + #endif // ARDUINO_ARCH_SAMD