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

A digital output, used for setting the state of a pin. More...

#include <DigitalOut.h>

Public Member Functions

 DigitalOut (PinName pin)
 Create a DigitalOut connected to the specified pin. More...
 
 DigitalOut (PinName pin, int value)
 Create a DigitalOut 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...
 
int is_connected ()
 Return the output setting, represented as 0 or 1 (int) More...
 
DigitalOutoperator= (int value)
 A shorthand for write() More...
 
DigitalOutoperator= (DigitalOut &rhs)
 A shorthand for write() using the assignment operator which copies the state from the DigitalOut argument. More...
 
 operator int ()
 A shorthand for read() More...
 

Detailed Description

A digital output, used for setting the state of a pin.

Note
Synchronization level: Interrupt safe

Example:

// Toggle a LED
#include "mbed.h"
DigitalOut led(LED1);
int main() {
while(1) {
led = !led;
ThisThread::sleep_for(200);
}
}
A digital output, used for setting the state of a pin.
Definition: DigitalOut.h:55

Definition at line 51 of file DigitalOut.h.

Constructor & Destructor Documentation

◆ DigitalOut() [1/2]

DigitalOut ( PinName  pin)

Create a DigitalOut connected to the specified pin.

Parameters
pinDigitalOut pin to connect to

Definition at line 62 of file DigitalOut.h.

◆ DigitalOut() [2/2]

DigitalOut ( PinName  pin,
int  value 
)

Create a DigitalOut connected to the specified pin.

Parameters
pinDigitalOut pin to connect to
valuethe initial pin value

Definition at line 73 of file DigitalOut.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 84 of file DigitalOut.h.

◆ read()

int read ( )

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

Returns
an integer representing the output setting of the pin, 0 for logical 0, 1 for logical 1

Definition at line 96 of file DigitalOut.h.

◆ 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 108 of file DigitalOut.h.

◆ operator=() [1/2]

DigitalOut & operator= ( int  value)

A shorthand for write()

See also
DigitalOut::write()
DigitalIn button(BUTTON1);
DigitalOut led(LED1);
led = button; // Equivalent to led.write(button.read())
A digital input, used for reading the state of a pin.
Definition: DigitalIn.h:60

Definition at line 122 of file DigitalOut.h.

◆ operator=() [2/2]

DigitalOut & operator= ( DigitalOut rhs)

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

See also
DigitalOut::write()

◆ operator int()

operator int ( )

A shorthand for read()

See also
DigitalOut::read()
DigitalIn button(BUTTON1);
DigitalOut led(LED1);
led = button; // Equivalent to led.write(button.read())

Definition at line 143 of file DigitalOut.h.