Skip to content
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

Support angle and microseconds for nrf52, renesasm stm32f4 #135

Open
wants to merge 2 commits 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
15 changes: 8 additions & 7 deletions src/nrf52/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ void Servo::detach()

void Servo::write(int value)
{
if (value < 0)
value = 0;
else if (value > 180)
value = 180;
value = map(value, 0, 180, MIN_PULSE, MAX_PULSE);

writeMicroseconds(value);
if(value < MIN_PULSE_WIDTH) {
if (value < 0)
value = 0;
else if (value > 180)
value = 180;
value = map(value, 0, 180, MIN_PULSE, MAX_PULSE);
}
this->writeMicroseconds(value);
}


Expand Down
9 changes: 6 additions & 3 deletions src/renesas/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,15 @@ void Servo::detach()
}
}

void Servo::write(int angle)
void Servo::write(int value)
{
if (servoIndex != SERVO_INVALID_INDEX) {
ra_servo_t *servo = &ra_servos[servoIndex];
angle = constrain(angle, 0, 180);
writeMicroseconds(map(angle, 0, 180, servo->period_min, servo->period_max));
if(value < MIN_PULSE_WIDTH) {
value = constrain(value, 0, 180);
value = map(value, 0, 180, servo->period_min, servo->period_max);
}
writeMicroseconds(value);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/stm32f4/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ bool Servo::detach() {
return true;
}

void Servo::write(int degrees) {
degrees = constrain(degrees, this->minAngle, this->maxAngle);
this->writeMicroseconds(ANGLE_TO_US(degrees));
void Servo::write(int value) {
if(value < MIN_PULSE_WIDTH) {
value = constrain(value, this->minAngle, this->maxAngle);
value = ANGLE_TO_US(value);
}
this->writeMicroseconds(value);
}

int Servo::read() const {
Expand Down