Retour Clement
This commit is contained in:
parent
dea01d3e84
commit
15bd7c7741
@ -1,22 +1,29 @@
|
|||||||
#include "ServoMotorComponent.h"
|
#include "ServoMotorComponent.h"
|
||||||
|
|
||||||
ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod) {
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Functions for setting up the ServoMotor
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* Prepares the ServoMotor.
|
||||||
|
*/
|
||||||
|
ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod, float step) {
|
||||||
this->PIN = PIN;
|
this->PIN = PIN;
|
||||||
this->myservo.attach(PIN);
|
this->myservo.attach(PIN);
|
||||||
this->desiredposition = Position::MIDDLE;
|
this->desiredposition = Position::MIDDLE;
|
||||||
this->currentPosition = 0;
|
this->currentPosition = 32;
|
||||||
this->lastUpTime = millis();
|
this->lastUpTime = millis();
|
||||||
this->updatePeriod = updatePeriod;
|
this->updatePeriod = updatePeriod;
|
||||||
|
this->step = step;
|
||||||
|
this->myservo.write(this->PIN, this->currentPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServoMotorComponent::getCurrentPosition() {
|
/**
|
||||||
return this->myservo.read(this->PIN);
|
* Set the desired position
|
||||||
}
|
* @desiredPosition: Give desired position
|
||||||
|
*/
|
||||||
void ServoMotorComponent::setCurrentPosition() {
|
|
||||||
this->currentPosition = this->myservo.read(this->PIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
|
void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
|
||||||
switch (desiredPosition) {
|
switch (desiredPosition) {
|
||||||
case Position::LEFT:
|
case Position::LEFT:
|
||||||
@ -34,6 +41,9 @@ void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a new servoMotor position when it's necessary
|
||||||
|
*/
|
||||||
void ServoMotorComponent::refresh() {
|
void ServoMotorComponent::refresh() {
|
||||||
if (this->desiredposition == this->currentPosition
|
if (this->desiredposition == this->currentPosition
|
||||||
|| millis() - this->lastUpTime <= this->updatePeriod) return;
|
|| millis() - this->lastUpTime <= this->updatePeriod) return;
|
||||||
@ -46,11 +56,4 @@ void ServoMotorComponent::refresh() {
|
|||||||
}
|
}
|
||||||
this->lastUpTime = millis();
|
this->lastUpTime = millis();
|
||||||
this->myservo.write(this->PIN, this->currentPosition);
|
this->myservo.write(this->PIN, this->currentPosition);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ServoMotorComponent::setPin(int PIN) {
|
|
||||||
this->PIN = PIN;
|
|
||||||
this->myservo.attach(PIN);
|
|
||||||
return;
|
|
||||||
}
|
}
|
@ -12,21 +12,18 @@ enum Position {
|
|||||||
class ServoMotorComponent
|
class ServoMotorComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServoMotorComponent(int PIN, unsigned long updatePeriod);
|
ServoMotorComponent(int PIN, unsigned long updatePeriod, float step = 1);
|
||||||
~ServoMotorComponent() = default;
|
|
||||||
int getCurrentPosition();
|
|
||||||
void setCurrentPosition();
|
|
||||||
void setDesiredPosition(Position desiredPosition);
|
void setDesiredPosition(Position desiredPosition);
|
||||||
void setPin(int PIN);
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int PIN;
|
int PIN;
|
||||||
int currentPosition;
|
float currentPosition;
|
||||||
int desiredposition;
|
float desiredposition;
|
||||||
Servo myservo;
|
Servo myservo;
|
||||||
unsigned long lastUpTime;
|
unsigned long lastUpTime;
|
||||||
unsigned long updatePeriod;
|
unsigned long updatePeriod;
|
||||||
|
float step;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,17 +2,28 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "DolibarrClient.h"
|
#include "DolibarrClient.h"
|
||||||
|
|
||||||
|
int initialize_wifi(WifiConfig wifi) {
|
||||||
|
WiFiClass::mode(WIFI_STA); //Optional
|
||||||
|
WiFi.setSleep(false);
|
||||||
|
WiFi.begin(wifi.ssid, wifi.password);
|
||||||
|
Serial.print("Connecting ");
|
||||||
|
while(WiFiClass::status() != WL_CONNECTED){
|
||||||
|
delay(WAITING_WIFI_DELAY);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
Serial.println("Connected to the WiFi network");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Program::Program() {
|
Program::Program() {
|
||||||
this->servo = new ServoMotorComponent(2);
|
Serial.begin(MONITOR_SPEED);
|
||||||
|
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
|
||||||
|
struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
|
||||||
|
initialize_wifi(wifi_c);
|
||||||
|
this->client = new DolibarrClient(dolibarr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::loop() {
|
void Program::loop() {
|
||||||
// this->servo->goLeft();
|
|
||||||
// delay(3000);
|
|
||||||
this->servo->goMiddle();
|
|
||||||
// delay(3000);
|
|
||||||
// this->servo->goRight();
|
|
||||||
// delay(3000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user