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 this program

#include "mbed.h"
 
DigitalInOut pin(p5);
 
int main() {
    pin.output();
    pin = 0;     
    wait_us(500);
    pin.input();
    wait_us(500);
}

» Import this program

#include "mbed.h"
 
DigitalInOut pin(PTB0);
 
int main() {
    pin.output();
    pin = 0;     
    wait_us(500);
    pin.input();
    wait_us(500);
}

API

API summary

» Import latest build into a program

Public Member Functions

  DigitalInOut (PinName pin)
  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.
DigitalInOut operator= (int value)
  A shorthand for write()
  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



1 comment:

04 Sep 2012

Is the delay a must?

Posting comments for this page has been disabled