DigitalInOut

Mbed OS 2 and Mbed OS 5

This is the handbook for Mbed OS 2. If you’re working with Mbed OS 5, please see the Mbed OS 5 documentation. For the latest DigitalInOut API, please see DigitalInOut.

The DigitalInOut interface is used as a bi-directional digital pin, used to read the value of a digital pin when set as an input, or write the value when set as an output.

Any of the numbered mbed pins can be used as a DigitalInOut.

Hello World!

Import program

00001 #include "mbed.h"
00002  
00003 DigitalInOut pin(p5);
00004  
00005 int main() {
00006     pin.output();
00007     pin = 0;     
00008     wait_us(500);
00009     pin.input();
00010     wait_us(500);
00011 }

[Repository '/users/mbed_official/code/DigitalInOut_HelloWorld_FRDM-KL25Z/docs/tip/main_8cpp_source.html' not found]

API

API summary

Import library

Public Member Functions

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

Interface

The DigitalInOut Interface can be used on any pin with a blue label.

/media/uploads/chris/pinout-thumbnails.jpg
See the Pinout page for more details