[feature/ServoMotor] - change servo librarie
This commit is contained in:
32
lib/ServoMotorComponent/src/ServoMotorComponent.cpp
Normal file
32
lib/ServoMotorComponent/src/ServoMotorComponent.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "ServoMotorComponent.h"
|
||||
|
||||
ServoMotorComponent::ServoMotorComponent(int PIN) {
|
||||
this->PIN = PIN;
|
||||
this->position = 0;
|
||||
this->myservo.attach(PIN);
|
||||
}
|
||||
|
||||
void ServoMotorComponent::goLeft() {
|
||||
this->myservo.write(this->PIN, 0);
|
||||
this->position = 0;
|
||||
}
|
||||
|
||||
void ServoMotorComponent::goRight() {
|
||||
this->myservo.write(this->PIN, 180);
|
||||
|
||||
this->position = 180;
|
||||
}
|
||||
|
||||
void ServoMotorComponent::goMiddle() {
|
||||
this->myservo.write(this->PIN, 90);
|
||||
this->position = 90;
|
||||
}
|
||||
|
||||
int ServoMotorComponent::getPosition() {
|
||||
return this->position;
|
||||
}
|
||||
|
||||
void ServoMotorComponent::setPin(int PIN) {
|
||||
this->PIN = PIN;
|
||||
this->myservo.attach(PIN);
|
||||
}
|
27
lib/ServoMotorComponent/src/ServoMotorComponent.h
Normal file
27
lib/ServoMotorComponent/src/ServoMotorComponent.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef SERVOMOTOT_COMPONENT_H
|
||||
#define SERVOMOTOT_COMPONENT_H
|
||||
|
||||
#include <Servo.h>
|
||||
|
||||
class ServoMotorComponent
|
||||
{
|
||||
public:
|
||||
ServoMotorComponent(int PIN);
|
||||
~ServoMotorComponent() = default;
|
||||
void goLeft();
|
||||
void goRight();
|
||||
void goMiddle();
|
||||
int getPosition();
|
||||
void setPin(int PIN);
|
||||
|
||||
private:
|
||||
int PIN;
|
||||
int position;
|
||||
Servo myservo;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //SERVOMOTOT_COMPONENT_H
|
Reference in New Issue
Block a user