Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Purpose

Get the value of a Digital Input (DI) of the board.

When to use

Whenever you need to use the state of a DI.

Where to use

Most probably in the void loop() part of your .ino file, since we’d usually want to actively monitor the value.

Info

Click here to learn more on the DIOs of the 9880 board.

Note

This function requires the use of the following CrcLib functions at some point of your .ino file in order to work properly:

Returns

This function returns state of the DI mentioned as the function’s argument as an unsigned char type. The value returned will be either one of these two possible values:

  • HIGH, if voltage is applied to the SIG pin of the digital port.

  • LOW, if no voltage is applied to the SIG pin of the digital port.

Main prototype and parameters

static void Crc::unsigned char CrcLib::SetDigitalPinModeGetDigitalInput(unsigned char pin, unsigned char mode)

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.mode: The mode you want to set the pin toread the state of. Must be of the type unsigned char. Needs to be one of the following:

  • INPUT, if you are using the digital pin as as input.

  • OUTPUT, if you are using the digital pin as as output

    .

Overloads

This function does not have any overloads. It can only be used as described by the main prototype.

Examples

code
Expand
title#1: We want to connect a digital sensor, like a limit switch, put the state of a button, connected to DIO Port 5. We want to connect a small light or a relay control signal, to DIO Port 9.
, into a variable, to be used eslewhere in the program.
Code Block
languagecpp
#include <CrcLib.h>

// Variable declaration
bool ButtonState;

void setup() {
    CrcLib::Initialize();

    CrcLib::SetDigitalPinMode(CRC_DIG_5, INPUT); //Set up DIO Port 5 as an Input

    /* 
    The rest of your setup code
    ...
     */
}
void loop() {
    CrcLib::Update();

    //The variable ButtonState will have the same value as DIO Port 5
    ButtonState = CrcLib::GetDigitalInput(CRC_DIG_5);
    
    /* 
    The rest of your looping code
    ...
    */
}

More on this function

Info
Why does this function return HIGH/ LOW, instead of
TRUE
true /
FALSE?
false?

The Arduino environment, when speaking of voltage, uses the constant HIGH to represent its presence and LOW to represent its absence. In electronics, a voltage presence (or when is is greater than a certain value) is usually represented by true, while an absence of voltage (or when it is lower than a certain value) is usually represented by false.

More on this here.

Related articles

Filter by label (Content by label)
sorttitle
excerptTyperich content
cqllabel = "ar-digital_io"