Purpose
Sets a Digital Output (DIO) Pin to a desired value.
When to use
Every time you want the state of a DO 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.
Info |
---|
Click here to learn more on the DIOs of the 9880 board. |
Note |
---|
This function requires the use of the following functions at some point of your |
Returns
This function does not return a value once it has completed its tasks.
Main prototype and parameters
static void Crc::CrcLib::SetDigitalOutput(unsigned char pin, unsigned char value)
The following parameters must be passed to the function for it to work properly:
pin
: The name of the digital pin you want to set. Must be of the typeunsigned char
. Must have been initialized as an output usingCrcLib::SetDigitalPinMode()
beforehand.value
: The value you want to set the pin to. Must be of the typeunsigned char
. Needs to be one of the following:LOW
, to output 0V on the given DO pin.HIGH,
to output 5V on the given DO pin.
Overloads
This function does not have any overloads. It can only be used as described by the main prototype.
Examples
Expand | |||||
---|---|---|---|---|---|
| |||||
|
Expand | |||||
---|---|---|---|---|---|
| |||||
|
More on this function
Info |
---|
Why not use the native Arduino function digitalWrite() instead of CrcLib::SetDigitalOutput() ?We recommend using CrcLib::SetDigitalOutput() because it adds a few layers of validation to make sure you don't assign a value to an unsafe pin. |
Info |
---|
How does Example #2 work ?In the Arduino world,
The Therefore, the line |
Info |
---|
Why use the method used in Example #2 instead of the one shown in Example #1 ?Both methods are legal and can be used. Although #1 is easier to code and read for novice programmers, #2 would be the preferred one since it requires less code to be executed by the micro-controller on every code execution loop. Less code to be executed means a faster program. We’re talking a couple microseconds here, so in a CRC Robotics Competition use case it doesn’t really matter. But in a time critical application, with a code of containing thousands of lines, these small gains really add up! |