Digital Entity

BrainStem modules may have the ability to read, write or manipulate a digital pin. Digital I/O capabilities will be dictated by the module hardware being used. Module specifics that include the quantity of digital entities and details for their capacities will be described in that module’s datasheet.

State (Get/Set)

digital [ index ] . getState <= (unsigned char) state
digital [ index ] . setState => (unsigned char) state

Gets or Sets the digital I/O Value.

For gets the digital input state will be reported in a boolean fashion. Voltage threshold tolerance details for the target module will be described in the datasheet.

For sets the digital output state will be asserted logic high or logic low. Voltage threshold details for the target module will be described in the datasheet.

Configuration (Get/Set)

digital [ index ] . getConfiguration <= (unsigned char) configuration
digital [ index ] . setConfiguration => (unsigned char) configuration

Gets or Sets the digital pin configuration.

Some digital entities may be single purpose functionality or can be configured for multiple behaviors depending on the hardware.

Digital entities that are capable of different operating configurations can be explicitly set to operate in a desired configuration mode when possible. Defaults for most digital entities are typically as inputs, but will vary by module hardware.

Available configurations for the digital entities:

Function

Typedef Constant (C++)

Typedef Constant (Python)

Val

Digital Input

digitalConfigurationInput

CONFIGURATION_INPUT

0

Digital Output

digitalConfigurationOutput

CONFIGURATION_OUTPUT

1

RCServo Input

digitalConfigurationRCServoInput

CONFIGURATION_RCSERVO_INPUT

2

RCServo Output

digitalConfigurationRCServoOutput

CONFIGURATION_RCSERVO_OUTPUT

3

High Z State

digitalConfigurationHiZ

CONFIGURATION_HIGHZ

4

Input Pull Up

digitalConfigurationInputPullUp

CONFIGURATION_INPUT_PULL_UP

0

Input No Pull

digitalConfigurationInputNoPull

CONFIGURATION_INPUT_NO_PULL

4

Input Pull Down

digitalConfigurationInputPullDown

CONFIGURATION_INPUT_PULL_DOWN

5

Signal Output

digitalConfigurationSignalOutput

CONFIGURATION_SIGNAL_OUTPUT

6

Signal Input

digitalConfigurationSignalInput

CONFIGURATION_SIGNAL_INPUT

7

Note

When using the High Z State configuration the pin and pull-ups are disconnected internally leaving the external pin floating. A get or set of the state will return in an error.

See the RCServo Entity for more information on its configuration.

Code Examples

C++

// All commands return aErr values when errors are encountered and aErrNone on
// success.

stem.digital[0].getState(&state); // gets the current digital state for channel 0
stem.digital[3].setState(1); // sets the digital output state to logic high on channel 3
stem.digital[0].setConfiguration(digitalConfigurationInput);

Reflex

stem.digital[0].getState(state); // gets the current digital state for channel 0
stem.digital[3].setState(1); // sets the digital output state to logic high on channel 3

Python

state = stem.digital[3].getState() # gets the value of digital channel 3 into variable state
stem.digital[3].setState(1) #  sets the digital on channel 3 to a logic high