[feature/Servo_Motor] - add ServoMotorComponent
This commit is contained in:
parent
6e9a59bb00
commit
f3dc069f3b
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"new": "cpp"
|
||||||
|
}
|
||||||
|
}
|
32
lib/ServoMotorComponent/ServoMotorComponent.cpp
Normal file
32
lib/ServoMotorComponent/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);
|
||||||
|
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);
|
||||||
|
}
|
27
lib/ServoMotorComponent/ServoMotorComponent.h
Normal file
27
lib/ServoMotorComponent/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
|
@ -55,6 +55,7 @@ lib_deps =
|
|||||||
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
|
||||||
m5stack/Module_GRBL_13.2@^0.0.3 ; M5 Lib pour Stepper (GRBL)
|
m5stack/Module_GRBL_13.2@^0.0.3 ; M5 Lib pour Stepper (GRBL)
|
||||||
|
arduino-libraries/Servo@^1.2.1 ; Lib pour le Servo Motor
|
||||||
; example:
|
; example:
|
||||||
; erropix/ESP32 AnalogWrite@0.2
|
; erropix/ESP32 AnalogWrite@0.2
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user