feature/servo_motor_component #17
@ -1,50 +1,56 @@
|
||||
#include "ServoMotorComponent.h"
|
||||
|
||||
ServoMotorComponent::ServoMotorComponent(int PIN) {
|
||||
ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod) {
|
||||
this->PIN = PIN;
|
||||
this->position = 30;
|
||||
this->speed = 100;
|
||||
this->easing = 0.5;
|
||||
this->myservo.attach(PIN);
|
||||
this->desiredposition = Position::MIDDLE;
|
||||
this->currentPosition = 0;
|
||||
this->lastUpTime = millis();
|
||||
this->updatePeriod = updatePeriod;
|
||||
}
|
||||
|
||||
void ServoMotorComponent::goLeft() {
|
||||
this->myservo.write(this->PIN, 52, this->speed, this->easing);
|
||||
this->position = 0;
|
||||
int ServoMotorComponent::getCurrentPosition() {
|
||||
return this->myservo.read(this->PIN);
|
||||
}
|
||||
|
||||
void ServoMotorComponent::goRight() {
|
||||
this->myservo.write(this->PIN, 18, this->speed, this->easing);
|
||||
|
||||
this->position = 180;
|
||||
void ServoMotorComponent::setCurrentPosition() {
|
||||
|
||||
this->currentPosition = this->myservo.read(this->PIN);
|
||||
}
|
||||
|
||||
void ServoMotorComponent::goMiddle() {
|
||||
this->myservo.write(this->PIN, 32, this->speed, this->easing);
|
||||
this->position = 90;
|
||||
void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
|
||||
Clement
commented
Nom des variables pas claire Nom des variables pas claire
|
||||
switch (desiredPosition) {
|
||||
case Position::LEFT:
|
||||
this->desiredposition = 52;
|
||||
break;
|
||||
case Position::MIDDLE:
|
||||
this->desiredposition = 32;
|
||||
break;
|
||||
case Position::RIGHT:
|
||||
this->desiredposition = 18;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int ServoMotorComponent::getPosition() {
|
||||
return this->position;
|
||||
|
||||
void ServoMotorComponent::refresh() {
|
||||
if (this->desiredposition == this->currentPosition
|
||||
|| millis() - this->lastUpTime <= this->updatePeriod) return;
|
||||
|
||||
if (this->currentPosition > this->desiredposition) {
|
||||
this->currentPosition--;
|
||||
Clement
commented
Limite faire en sorte de pouvoir configurer le pas dans le constructeur (avec une valeur par défaut) Limite faire en sorte de pouvoir configurer le pas dans le constructeur (avec une valeur par défaut)
en double ou float
|
||||
}
|
||||
if (this->currentPosition < this->desiredposition) {
|
||||
this->currentPosition++;
|
||||
}
|
||||
this->lastUpTime = millis();
|
||||
Clement marked this conversation as resolved
Outdated
Clement
commented
typo ctrl C typo ctrl C
|
||||
this->myservo.write(this->PIN, this->currentPosition);
|
||||
}
|
||||
|
||||
|
||||
void ServoMotorComponent::setPin(int PIN) {
|
||||
Mathis marked this conversation as resolved
Outdated
Clement
commented
pas besoins car déja fait dans constructeur pas besoins car déja fait dans constructeur
|
||||
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;
|
||||
}
|
||||
}
|
@ -3,26 +3,30 @@
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
enum Position {
|
||||
LEFT,
|
||||
MIDDLE,
|
||||
RIGHT
|
||||
};
|
||||
|
||||
class ServoMotorComponent
|
||||
Mathis marked this conversation as resolved
Outdated
Clement
commented
il n'y a pas d'interface il n'y a pas d'interface
|
||||
{
|
||||
public:
|
||||
ServoMotorComponent(int PIN);
|
||||
ServoMotorComponent(int PIN, unsigned long updatePeriod);
|
||||
~ServoMotorComponent() = default;
|
||||
Clement
commented
tu peut viré le destructeur tu peut viré le destructeur
|
||||
void goLeft();
|
||||
void goRight();
|
||||
void goMiddle();
|
||||
int getPosition();
|
||||
int getCurrentPosition();
|
||||
void setCurrentPosition();
|
||||
Clement
commented
met des commentaire doxygen sur tes fonction met des commentaire doxygen sur tes fonction
|
||||
void setDesiredPosition(Position desiredPosition);
|
||||
void setPin(int PIN);
|
||||
void pause();
|
||||
void setSpeed(int speed);
|
||||
void setEasing(float easing);
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
int PIN;
|
||||
int position;
|
||||
int speed;
|
||||
float easing;
|
||||
int currentPosition;
|
||||
int desiredposition;
|
||||
Servo myservo;
|
||||
unsigned long lastUpTime;
|
||||
unsigned long updatePeriod;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user
???