Mbed OS Reference
Loading...
Searching...
No Matches
DigitalInOut Class Reference

A digital input/output, used for setting or reading a bi-directional pin. More...

#include <DigitalInOut.h>

Public Member Functions

 DigitalInOut (PinName pin)
 Create a DigitalInOut connected to the specified pin. More...
 
 DigitalInOut (PinName pin, PinDirection direction, PinMode mode, int value)
 Create a DigitalInOut connected to the specified pin. More...
 
void write (int value)
 Set the output, specified as 0 or 1 (int) More...
 
int read ()
 Return the output setting, represented as 0 or 1 (int) More...
 
void output ()
 Set as an output. More...
 
void input ()
 Set as an input. More...
 
void mode (PinMode pull)
 Set the input pin mode. More...
 
int is_connected ()
 Return the output setting, represented as 0 or 1 (int) More...
 
DigitalInOutoperator= (int value)
 A shorthand for write() More...
 
DigitalInOutoperator= (DigitalInOut &rhs)
 A shorthand for write() using the assignment operator which copies the state from the DigitalInOut argument. More...
 
 operator int ()
 A shorthand for read() More...
 

Detailed Description

A digital input/output, used for setting or reading a bi-directional pin.

Note
Synchronization level: Interrupt safe

Definition at line 36 of file DigitalInOut.h.

Constructor & Destructor Documentation

◆ DigitalInOut() [1/2]

DigitalInOut ( PinName  pin)

Create a DigitalInOut connected to the specified pin.

Parameters
pinDigitalInOut pin to connect to

Definition at line 47 of file DigitalInOut.h.

◆ DigitalInOut() [2/2]

DigitalInOut ( PinName  pin,
PinDirection  direction,
PinMode  mode,
int  value 
)

Create a DigitalInOut connected to the specified pin.

Parameters
pinDigitalInOut pin to connect to
directionthe initial direction of the pin
modethe initial mode of the pin
valuethe initial value of the pin if is an output

Definition at line 60 of file DigitalInOut.h.

Member Function Documentation

◆ write()

void write ( int  value)

Set the output, specified as 0 or 1 (int)

Parameters
valueAn integer specifying the pin output value, 0 for logical 0, 1 (or any other non-zero value) for logical 1

Definition at line 71 of file DigitalInOut.h.

◆ read()

int read ( )

Return the output setting, represented as 0 or 1 (int)

Returns
an integer representing the output setting of the pin if it is an output, or read the input if set as an input

Definition at line 83 of file DigitalInOut.h.

◆ output()

void output ( )

Set as an output.

◆ input()

void input ( )

Set as an input.

◆ mode()

void mode ( PinMode  pull)

Set the input pin mode.

Parameters
pullPullUp, PullDown, PullNone, OpenDrain

◆ is_connected()

int is_connected ( )

Return the output setting, represented as 0 or 1 (int)

Returns
Non zero value if pin is connected to uc GPIO 0 if gpio object was initialized with NC

Definition at line 109 of file DigitalInOut.h.

◆ operator=() [1/2]

DigitalInOut & operator= ( int  value)

A shorthand for write()

See also
DigitalInOut::write()
DigitalInOut inout(PIN);
DigitalIn button(BUTTON1);
inout.output();
inout = button; // Equivalent to inout.write(button.read())
A digital input, used for reading the state of a pin.
Definition: DigitalIn.h:60
A digital input/output, used for setting or reading a bi-directional pin.
Definition: DigitalInOut.h:40

Definition at line 125 of file DigitalInOut.h.

◆ operator=() [2/2]

DigitalInOut & operator= ( DigitalInOut rhs)

A shorthand for write() using the assignment operator which copies the state from the DigitalInOut argument.

See also
DigitalInOut::write()

◆ operator int()

operator int ( )

A shorthand for read()

See also
DigitalInOut::read()
DigitalInOut inout(PIN);
DigitalOut led(LED1);
inout.input();
led = inout; // Equivalent to led.write(inout.read())
A digital output, used for setting the state of a pin.
Definition: DigitalOut.h:55

Definition at line 148 of file DigitalInOut.h.