diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..03ba48b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "new": "cpp" + } +} \ No newline at end of file diff --git a/lib/ServoMotorComponent/ServoMotorComponent.cpp b/lib/ServoMotorComponent/ServoMotorComponent.cpp new file mode 100644 index 0000000..11c6871 --- /dev/null +++ b/lib/ServoMotorComponent/ServoMotorComponent.cpp @@ -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); +} diff --git a/lib/ServoMotorComponent/ServoMotorComponent.h b/lib/ServoMotorComponent/ServoMotorComponent.h new file mode 100644 index 0000000..c5a08c1 --- /dev/null +++ b/lib/ServoMotorComponent/ServoMotorComponent.h @@ -0,0 +1,27 @@ +#ifndef SERVOMOTOT_COMPONENT_H +#define SERVOMOTOT_COMPONENT_H + +#include + +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 diff --git a/platformio.ini b/platformio.ini index 9724c56..fb42dd8 100644 --- a/platformio.ini +++ b/platformio.ini @@ -54,6 +54,7 @@ lib_deps = bblanchon/ArduinoJson@^6.21.3 ; JSON serializer et deserializer m5stack/M5Stack@^0.4.5 ; M5 Lib m5stack/M5GFX@^0.1.9 ; M5 Lib pour le LCD + arduino-libraries/Servo@^1.2.1 ; Lib pour le Servo Motor ; example: ; erropix/ESP32 AnalogWrite@0.2