Loading [MathJax]/extensions/tex2jax.js
SensESP 3.1.0
Universal Signal K sensor toolkit ESP32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sensesp::PWMOutput Class Reference

DEPRECATED. Use Android native ledcAttach and ledcWrite instead. More...

#include <sensesp/system/pwm_output.h>

Inheritance diagram for sensesp::PWMOutput:
[legend]

Public Member Functions

 PWMOutput (int pin=-1, int pwm_channel=-1, int channel_frequency=5000, int channel_resolution=13) __attribute__((deprecated))
 
virtual void set (const float &new_value) override
 
- Public Member Functions inherited from sensesp::ValueConsumer< float >
virtual void set_input (const float &new_value)
 
void connect_from (ValueProducer< float > *producer)
 

Protected Member Functions

int assign_channel (int pin, int pwm_channel=-1)
 
void set_pwm (float value)
 

Static Protected Member Functions

static std::map< uint8_t, int8_t > & channel_map ()
 

Protected Attributes

int channel_frequency_
 
int channel_resolution_
 
int pwmrange_
 
uint8_t pwm_channel_ {}
 

Additional Inherited Members

- Public Types inherited from sensesp::ValueConsumer< float >
using input_type
 

Detailed Description

DEPRECATED. Use Android native ledcAttach and ledcWrite instead.

This class works by defining a "PWM channel". GPIO pins are assigned to a channel, and then the channel is used when setting the pwm value. The pwm value is a float number between 0.0 and 1.0, interpreted as a percentage of the maximum duty cycle possible.

Channels can be auto-assigned to a pin or they can be declared explicitly in your code. The PWM value is set either by calling set_pwm(), or by using an instance of PWMOutput and calling the set() method as defined in ValueConsumer<>.

On an esp32, the "channel" corresponds to one of the timer channels available on the onboard chip. Explicit declaration of a channel may or may not be necessary depending on other libraries that you may be using. Unless you have a need to use an explicit channel (e.g. if some other software is already using a particular esp32 timer channel), the channel auto-assign feature is the easiest to use. In either event, using this channel number allows the same code to work on either platform.

Definition at line 33 of file pwm_output.h.

Constructor & Destructor Documentation

◆ PWMOutput()

sensesp::PWMOutput::PWMOutput ( int pin = -1,
int pwm_channel = -1,
int channel_frequency = 5000,
int channel_resolution = 13 )
inline

Creates an instance of a PWMOutput ValueConsumer.

Parameters
pinThe GPIO pin used to output the pwm signal. Pass -1 if this instance does not manage a specific pin. Using -1 is only valid if channel assignments have been explicitly made by calling PWMOutput::assign_channel()
pwm_channelThe pwm channel the GPIO pin is to be assigned to. Pass -1 if you would like the system to auto-select the next unassigned pin.

Definition at line 45 of file pwm_output.h.

Member Function Documentation

◆ assign_channel()

int sensesp::PWMOutput::assign_channel ( int pin,
int pwm_channel = -1 )
inlineprotected

Assigns the specified GPIO pin to the specified pwm channel.

Parameters
pinthe GPIO pin used for the pwm output
pwm_channelThe pwm_channel to the GPIO pin is assigned to. Passing -1 specifies you would like to use the next unassigned channel available.
Returns
The actual pwm channel assigned to the GPIO pin to the pin

Definition at line 85 of file pwm_output.h.

Here is the call graph for this function:

◆ channel_map()

static std::map< uint8_t, int8_t > & sensesp::PWMOutput::channel_map ( )
inlinestaticprotected

Definition at line 69 of file pwm_output.h.

Here is the caller graph for this function:

◆ set()

virtual void sensesp::PWMOutput::set ( const float & new_value)
inlineoverridevirtual

Sets the duty cycle of the specified pwm_channel to new_value. If pwm_channel is zero, the channel assigned when the PWMOutput instance was instantiated will be used.

Reimplemented from sensesp::ValueConsumer< float >.

Definition at line 62 of file pwm_output.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pwm()

void sensesp::PWMOutput::set_pwm ( float value)
inlineprotected

Sets duty cycle on specified pwm channel

Parameters
valueA number between 0.0 and 1.0, where 1.0 is the maximum duty cycle the output pin supports.

Definition at line 118 of file pwm_output.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ channel_frequency_

int sensesp::PWMOutput::channel_frequency_
protected

Definition at line 65 of file pwm_output.h.

◆ channel_resolution_

int sensesp::PWMOutput::channel_resolution_
protected

Definition at line 66 of file pwm_output.h.

◆ pwm_channel_

uint8_t sensesp::PWMOutput::pwm_channel_ {}
protected

Definition at line 74 of file pwm_output.h.

◆ pwmrange_

int sensesp::PWMOutput::pwmrange_
protected

Definition at line 67 of file pwm_output.h.


The documentation for this class was generated from the following file: