Adafruit Library
ws_ledc_servo.h
Go to the documentation of this file.
1 
18 #ifndef WS_ESP32_SERVO
19 #define WS_ESP32_SERVO
20 
22 
23 // from https://github.com/arduino-libraries/Servo/blob/master/src/Servo.h
24 #define MIN_PULSE_WIDTH 544
25 #define MAX_PULSE_WIDTH 2400
26 #define INVALID_SERVO 255
27 
28 #define DEFAULT_SERVO_FREQ 50
29 #define LEDC_TIMER_WIDTH \
30  12
31 
36 
37 typedef struct {
38  uint8_t nbr;
39  uint8_t isActive;
40 } ServoPin_t;
41 
43 typedef struct {
45 } servo_t;
46 
47 class ws_ledc;
48 
49 /************************************************************************************************/
56 /************************************************************************************************/
58 public:
59  ws_ledc_servo();
61  void setLEDCDriver(ws_ledc *ledcManager);
62  // The functions below are compatible with
63  // https://github.com/arduino-libraries/Servo/blob/master/src/Servo.h
64  uint8_t attach(int pin, int minPulseWidth, int maxPulseWidth, int servoFreq);
65  bool attached();
66  void detach();
67  void writeMicroseconds(int value);
68 
69 private:
70  servo_t _servo;
71  int _minPulseWidth;
72  int _maxPulseWidth;
73  ws_ledc *_ledcMgr;
74 };
75 #endif // WS_ESP32_SERVO
Definition: ws_ledc_servo.h:37
uint8_t isActive
True if the servo is enabled.
Definition: ws_ledc_servo.h:39
High-level interface for the ESP32/ESP32-Sx/ESP32-Cx LED Control (LEDC) peripheral. Instead of specifying a timer or channel, this class automatically allocates a channel and associates it with a pin. Underlying esp32-hal-ledc performs timer management and handles the low-level LEDC peripheral API calls.
Definition: ws_ledc.h:37
uint8_t attach(int pin, int minPulseWidth, int maxPulseWidth, int servoFreq)
Attaches a servo object to a pin.
Definition: ws_ledc_servo.cpp:62
void detach()
Detaches the servo (ledc timer) and de-allocates a servo object.
Definition: ws_ledc_servo.cpp:81
Definition: ws_ledc_servo.h:43
void writeMicroseconds(int value)
Writes the pulse width to the connected servo pin.
Definition: ws_ledc_servo.cpp:100
bool attached()
Returns if the servo is attached to a ledc timer.
Definition: ws_ledc_servo.cpp:92
High-level driver for servos for ESP32/ESP32-Sx/ESP32-Cx. This driver implements a subset of the func...
Definition: ws_ledc_servo.h:57
~ws_ledc_servo()
Destructor.
Definition: ws_ledc_servo.cpp:37
void setLEDCDriver(ws_ledc *ledcManager)
Sets a LEDC driver for use with servo objects.
Definition: ws_ledc_servo.cpp:47
ws_ledc_servo()
Constructor.
Definition: ws_ledc_servo.cpp:30
ServoPin_t Pin
Servo properties.
Definition: ws_ledc_servo.h:44
uint8_t nbr
Servo's pin number.
Definition: ws_ledc_servo.h:38