mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-07-05 02:01:42 +02:00
change motion from analogWrite to ledc, add fluent interface for motors
This commit is contained in:
33
src/motion/Motor.cpp
Normal file
33
src/motion/Motor.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "Motion.h"
|
||||
|
||||
Motor::Motor(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel){
|
||||
this->pin = pin;
|
||||
this->channel = channel;
|
||||
this->timer = timer;
|
||||
this->duty = 0;
|
||||
};
|
||||
|
||||
void Motor::begin(void){
|
||||
pinMode(this->pin,OUTPUT);
|
||||
ledc_channel_config_t channelConfig = {
|
||||
.gpio_num = this->pin,
|
||||
.speed_mode = LEDC_MODE,
|
||||
.channel = this->channel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = this->timer,
|
||||
.duty = 0, // Set duty to 0%
|
||||
.hpoint = 0
|
||||
};
|
||||
ledc_channel_config(&channelConfig);
|
||||
Serial.println("Motor begin done");
|
||||
};
|
||||
|
||||
void Motor::setSpeed(uint16_t duty){
|
||||
this->duty = duty;
|
||||
ledc_set_duty(LEDC_MODE,this->channel,duty);
|
||||
ledc_update_duty(LEDC_MODE,this->channel);
|
||||
};
|
||||
|
||||
uint16_t Motor::getSpeed(void){
|
||||
return this->duty;
|
||||
};
|
Reference in New Issue
Block a user