[feature/Servo_Motor] - add ServoMotorComponent

This commit is contained in:
Mathis 2023-11-16 09:55:30 +01:00
parent 88077f284e
commit 01b99d9716
4 changed files with 65 additions and 0 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"new": "cpp"
}
}

View File

@ -0,0 +1,32 @@
#include "ServoMotorComponent.h"
ServoMotorComponent::ServoMotorComponent(int PIN) {
this->PIN = PIN;
this->position = 0;
this->myservo.attach(PIN);
this->myservo.write(0);
}
void ServoMotorComponent::goLeft() {
this->myservo.write(0);
this->position = 0;
}
void ServoMotorComponent::goRight() {
this->myservo.write(180);
this->position = 180;
}
void ServoMotorComponent::goMiddle() {
this->myservo.write(90);
this->position = 90;
}
int ServoMotorComponent::getPosition() {
return this->position;
}
void ServoMotorComponent::setPin(int PIN) {
this->PIN = PIN;
this->myservo.attach(PIN);
}

View 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

View File

@ -54,6 +54,7 @@ lib_deps =
bblanchon/ArduinoJson@^6.21.3 ; JSON serializer et deserializer bblanchon/ArduinoJson@^6.21.3 ; JSON serializer et deserializer
m5stack/M5Stack@^0.4.5 ; M5 Lib m5stack/M5Stack@^0.4.5 ; M5 Lib
m5stack/M5GFX@^0.1.9 ; M5 Lib pour le LCD m5stack/M5GFX@^0.1.9 ; M5 Lib pour le LCD
arduino-libraries/Servo@^1.2.1 ; Lib pour le Servo Motor
; example: ; example:
; erropix/ESP32 AnalogWrite@0.2 ; erropix/ESP32 AnalogWrite@0.2