/
SetDigitalOutput()

SetDigitalOutput()

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 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 type unsigned char. Must have been initialized as an output using CrcLib::SetDigitalPinMode() beforehand.

  • value: The value you want to set the pin to. Must be of the type unsigned 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

#include <CrcLib.h> void setup() { CrcLib::Initialize(); //Set up DIO Port 1 as an Output CrcLib::SetDigitalPinMode(CRC_DIG_1, OUTPUT); /* The rest of your setup code ... */ } void loop() { CrcLib::Update(); //Check Green Triangle button state (on a ps3 controller) if(CrcLib::ReadDigitalChannel(BUTTON::COLORS_UP)==HIGH) //Button is pressed { CrcLib::SetDigitalOutput(CRC_DIG_1, LOW); //Output 0V on pin } if(CrcLib::ReadDigitalChannel(BUTTON::COLORS_UP)==LOW) //Button is not pressed { CrcLib::SetDigitalOutput(CRC_DIG_1, HIGH); //Output 5V on pin } /* The rest of your looping code ... */ }
#include <CrcLib.h> void setup() { CrcLib::Initialize(); //Set up DIO Port 1 as an Output CrcLib::SetDigitalPinMode(CRC_DIG_1, OUTPUT); /* The rest of your setup code ... */ } void loop() { CrcLib::Update(); //Mirrors the reversed state of the Green Triangle button (on a ps3 controller) to DIO Port 1 CrcLib::SetDigitalOutput(CRC_DIG_1, !(CrcLib::ReadDigitalChannel(BUTTON::COLORS_UP))); /* The rest of your looping code ... */ }

 

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.

Related articles

Related content

GetDigitalInput()
GetDigitalInput()
Read with this
SetDigitalPinMode()
SetDigitalPinMode()
More like this
CrcDuino Hardware Details
CrcDuino Hardware Details
Read with this
SetPwmOutput()
More like this
SetDigitalOutput() {FR}
SetDigitalOutput() {FR}
More like this
GetAnalogInput()
GetAnalogInput()
More like this