Digital Entity¶
API Documentation: [cpp] [python] [.NET] [CCA] [REST]
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 |
Signal Counter Input |
digitalConfigurationSignalCounterInput |
CONFIGURATION_SIGNAL_COUNTER_INPUT |
8 |
Link Input |
digitalConfigurationLinkInput |
CONFIGURATION_LINK_INPUT |
9 |
Link Output |
digitalConfigurationLinkOutput |
CONFIGURATION_LINK_OUTPUT |
10 |
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.
Link Channel (Get/Set)¶
digital [ index ] . getLinkChannel <= (unsigned char) channel
digital [ index ] . setLinkChannel => (unsigned char) channel
Configure one digital as Link Input and the other as Link Output (see the configuration table above), then set each side’s link channel to the peer’s entity index. Two digitals link when their linkchannel values match and the pair uses Link Input on one entity and Link Output on the other.
State All (Get/Set)¶
digital [ index ] . getStateAll <= (unsigned int) states
digital [ index ] . setStateAll => (unsigned int) states
Gets or sets the logical state of all digitals on the module in a single bit-mapped value. The number of digitals and valid bits depend on the module; see the product datasheet.
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);
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