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.
Click here to learn more on the DIOs of the 9880 board.
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 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
More on this function
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.
How does Example #2 work ?
In the Arduino world, LOW
means 0
and HIGH
means 1
. In C/C++, 0
means False
, and every other value means TRUE
. For more information on the meaning of LOW
and HIGH
, click here.
CrcLib::ReadDigitalChannel()
, when executed, returns the value of the remote controller button referred to in argument. The returned value is a bool
, meaning in the Arduino world that it’s either LOW
or HIGH
. If the button is pressed on the remote controller, HIGH
is returned, and LOW
is returned if it’s not. The means that, when the button is pressed, the line of code will be executed as the following: CrcLib::SetDigitalOutput(CRC_DIG_1, !(HIGH));
The !
operator, called Logical NOT, reverses the logical state of what’s following. TRUE
becomes False
, and vice-versa. The means that, when the button is pressed, the line of code will in fact be executed as the following: CrcLib::SetDigitalOutput(CRC_DIG_1, LOW);
Therefore, the line CrcLib::SetDigitalOutput(CRC_DIG_1, !(CrcLib::ReadDigitalChannel(BUTTON::COLORS_UP)));
will have, on every void loop()
execution, the CRC_DIG_1
port mirroring the reversed value of the Green Triangle Button.
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!
Add Comment