cleaned Motion class

This commit is contained in:
hhaupt
2024-06-14 02:23:12 +02:00
parent b1bb29aa1c
commit 2b0cd00ddd
2 changed files with 44 additions and 15 deletions

View File

@ -23,9 +23,24 @@ void Motor::begin(void){
};
void Motor::setSpeed(uint16_t duty){
this->duty = duty;
ledc_set_duty(LEDC_MODE,this->channel,duty);
ledc_update_duty(LEDC_MODE,this->channel);
int difference = duty-this->getSpeed();
if (difference > 0){
for(int i = 0;i<difference;i+=difference/20){
this->duty += difference/20;
ledc_set_duty(LEDC_MODE,this->channel,duty);
ledc_update_duty(LEDC_MODE,this->channel);
delayMicroseconds(5);
}
} else {
for(int i = 0;i>difference;i-=abs(difference/20)){
this->duty -= abs(difference/20);
ledc_set_duty(LEDC_MODE,this->channel,duty);
ledc_update_duty(LEDC_MODE,this->channel);
delayMicroseconds(5);
}
}
};
uint16_t Motor::getSpeed(void){