InitializePwmOutput()
Purpose
Enables the use of a PWM pin by initializing it with information relating to its characteristics.
When to use
Once for each PWM Pin used on the board. If you connect anything to a PWM pin, its mode should be set.
Where to use
At the beginning of your code execution, in the void setup()
part of your .ino
file, so that the pin is initialized before it is referred to by your code.
Click here to learn more on the PWM outputs of the CrcDuino board. It explains in particular why PWM port #1 to #4 can only be used with power motor controller.
CrcLib Error mode is triggered if a given PWM pin is initialized more than once. Make sure to only use InitializePwmOutput()
in void setup()
!
This function requires the use of the following functions at some point of your .ino
file in order to work properly:
Returns
This function does not return a value once it has completed its tasks.
Main prototype and parameters
static void CrcLib::InitializePwmOutput(unsigned char pin, int minPulseWidth, int maxPulseWidth, bool reverse)
The following parameters must be passed to the function for it to work properly:
pin
: The name of the PWM pin you want to initialize. Must be of the typeunsigned char
.minPulseWidth
: The minimum pulse width, in µs, of your servo motor. Must be of the typeint
.maxPulseWidth
: The maximum pulse width, in µs, of your servo motor. Must be of the typeint
.reverse
: Whether or not to invert the rotation direction of the servo. Must be of the typebool
.
Overloads
#1: Using default pulse width values, without the reverse feature
static void CrcLib::InitializePwmOutput(unsigned char pin)
It is the easiest, minimal way to use this function. A 1000µs min pulse width and 2000µs max pulse width will be used by default. The following parameters must be passed to the function for it to work properly:
pin
: The name of the PWM pin you want to initialize. Must be of the typeunsigned char
.
#2: Using default pulse width values, with the reverse feature
static void CrcLib::InitializePwmOutput(unsigned char pin, bool reverse)
A 1000µs min pulse width and 2000µs max pulse width will be used by default. The following parameters must be passed to the function for it to work properly:
pin
: The name of the PWM pin you want to set. Must be of the typeunsigned char
.reverse
: Whether or not to invert the rotation direction of the servo. Must be of the typebool
.
#3: Setting pulse width values, without the reverse feature
static void CrcLib::InitializePwmOutput(unsigned char pin, int minPulseWidth, int maxPulseWidth)
The following parameters must be passed to the function for it to work properly:
pin
: The name of the PWM pin you want to initialize. Must be of the typeunsigned char
.minPulseWidth
: The minimum pulse width, in µs, of your servo motor. Must be of the typeint
.maxPulseWidth
: The maximum pulse width, in µs, of your servo motor. Must be of the typeint
.
Examples
More on this function
Related articles