[ServoMotor] - rework servoMotor for adding speed and easing for movement

This commit is contained in:
2023-12-08 09:45:07 +01:00
parent 844cbf817c
commit 3c7aea15a9
4 changed files with 36 additions and 22 deletions

View File

@ -2,23 +2,25 @@
ServoMotorComponent::ServoMotorComponent(int PIN) {
this->PIN = PIN;
this->position = 0;
this->position = 30;
this->speed = 100;
this->easing = 0.5;
this->myservo.attach(PIN);
}
void ServoMotorComponent::goLeft() {
this->myservo.write(this->PIN, 0);
this->myservo.write(this->PIN, 52, this->speed, this->easing);
this->position = 0;
}
void ServoMotorComponent::goRight() {
this->myservo.write(this->PIN, 180);
this->myservo.write(this->PIN, 18, this->speed, this->easing);
this->position = 180;
}
void ServoMotorComponent::goMiddle() {
this->myservo.write(this->PIN, 90);
this->myservo.write(this->PIN, 32, this->speed, this->easing);
this->position = 90;
}
@ -29,4 +31,20 @@ int ServoMotorComponent::getPosition() {
void ServoMotorComponent::setPin(int PIN) {
this->PIN = PIN;
this->myservo.attach(PIN);
return;
}
void ServoMotorComponent::setSpeed(int speed) {
this->speed = speed;
return;
}
void ServoMotorComponent::pause() {
this->myservo.pause();
return;
}
void ServoMotorComponent::setEasing(float easing) {
this->easing = easing;
return;
}

View File

@ -13,10 +13,15 @@ public:
void goMiddle();
int getPosition();
void setPin(int PIN);
void pause();
void setSpeed(int speed);
void setEasing(float easing);
private:
int PIN;
int position;
int speed;
float easing;
Servo myservo;
};