Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Add servo detach API
Browse files Browse the repository at this point in the history
To reattach, simply call setAngle()
  • Loading branch information
facchinm committed Jan 16, 2019
1 parent 89907f5 commit 76f25f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extras/D11-Firmware/ServoMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

void ServoMotor::setDuty(int duty) {
this->duty = duty;
analogWrite(pin, duty);
if (duty < 0) {
pinMode(pin, INPUT);
} else {
analogWrite(pin, duty);
}
}

void ServoMotor::setFrequency(int frequency) {
Expand Down
4 changes: 4 additions & 0 deletions src/ServoMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ void mc::ServoMotor::setAngle(int angle) {
setData(SET_PWM_DUTY_CYCLE_SERVO, instance, map(angle,0,180,7,28));
}

void mc::ServoMotor::detach() {
setData(SET_PWM_DUTY_CYCLE_SERVO, instance, -1);
}

void mc::ServoMotor::setFrequency(int frequency) {
setData(SET_PWM_FREQUENCY_SERVO, instance, frequency);
}
1 change: 1 addition & 0 deletions src/ServoMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ServoMotor {
public:
ServoMotor();
void setAngle(int angle);
void detach();
void setFrequency(int frequency);
private:
int instance;
Expand Down

0 comments on commit 76f25f7

Please sign in to comment.