Recently changed pages
Debugging Debugging
mbed NXP LPC1768 mbed NXP LPC1768
Homepage Homepage
Compiler Tour Compiler Tour
Media Media
Serial Serial
Terminals Terminals
From the mbed microcontroller Handbook.

DigitalIn

/media/uploads/mbedofficial/digitalin_interfaces.png

The DigitalIn interface is used to read the value of a digital input pin.

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

Hello World!

Flash an LED while a DigitalIn is true

#include "mbed.h"

DigitalIn enable(p5);
DigitalOut led(LED1);

int main() {
    while(1) {
        if(enable) {
            led = !led;
        }
        wait(0.25);
    }
}

API

API summary

DigitalInA digital input, used for reading the state of a pin
Functions
DigitalInCreate a DigitalIn connected to the specified pin
readRead the input, represented as 0 or 1 (int)
modeSet the input pin mode
operator int()An operator shorthand for read()
class DigitalIn : public Base
A digital input, used for reading the state of a pin
DigitalIn(PinName pin,  
const char *name =  NULL)
Create a DigitalIn connected to the specified pin
int read()
Read the input, represented as 0 or 1 (int)
void mode(PinMode pull)
Set the input pin mode
operator int()
An operator shorthand for read()

Details

The pin input is logic '0' for any voltage on the pin below 0.8v, and '1' for any voltage above 2.0v. By default, the DigitalIn is setup with an internal pull-down resistor.

Examples

Boolean logic - NOT, AND, OR, XOR

#include "mbed.h"

DigitalIn a(p5);
DigitalIn b(p6);
DigitalOut z_not(LED1);
DigitalOut z_and(LED2);
DigitalOut z_or(LED3);
DigitalOut z_xor(LED4);

int main() {
    while(1) {
        z_not = !a;
        z_and = a && b;
        z_or = a || b;
        z_xor = a ^ b;
    }
}

Flash a LED while a pin is true, then exit

#include "mbed.h"

DigitalIn (p5);
DigitalOut led(LED1);

int main() {
    while(p5) {
        led = !led;
        wait(0.25);
    }
}

Related

To handle an interrupt, see InterruptIn




calendar Page history
Last modified moments ago, by user avatar Dan Ros   tag No tags | 0 replies     Share: Digg Tweet This

Please login to post comments.