Skip to content

Add a way to read the attached pin no for servos #5391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libraries/Servo/src/Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions libraries/Servo/src/avr/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions libraries/Servo/src/sam/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions libraries/Servo/src/samd/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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