SetPwmOutput()
Purpose
Sets a PWM Pin to a desired value.
When to use
Every time you want the value of a PWM pin to be modified.
Where to use
Most probably in the void loop()
part of your .ino
file. Can also be used at the beginning of your code execution, in the void setup()
part of your .ino
file, so that the pin is in a known state on startup.
Click here to learn more on the PWM outputs of the 9880 board. It explains in particular why PWM port #1 to #4 can only be used with power motor controller.
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::SetPwmOutput(unsigned char pin, char value)
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
. Must have been initialized using InitializePwmOutput() beforehand.value
: The value you want to set the pin to. Must be of the typesigned char
, so in the range [-128, 127].Setting a pin to
-128
will have the pin generating a pulse equal to the minimum pulse width previously set by InitializePwmOutput().Setting a pin to
127
will have the pin generating a pulse equal to the maximum pulse width previously set by InitializePwmOutput().Setting a pin to other values will have the pin generating a pulse mapped between the minimum and maximum pulse width previously set by InitializePwmOutput().
Overloads
This function does not have any overloads. It can only be used as described by the main prototype.
Examples
More on this function
Can I use the native Arduino function analogWrite() to control the PWM outputs ?
You could, but we strongly recommend against it if you don’t know what you are doing and don’t have a precise reason to do so. The analogWrite() native Arduino function controls PWM pins using the “normal” definition of PWM. Although PWM pins on the CrcDuino are PWM capable pins, they are used as Servo PWM pins by CrcLib, since the CRC Robotics Competition robots mostly use hobby type standard servos, continuous servo and PWM compatible power motor controllers. For more info on this, read this.