You are viewing an older revision! See the latest version
DigitalIn

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
Import library
Public Member Functions |
|
| 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()
|
|
| virtual struct rpc_method * | get_rpc_methods () |
|
Returns a pointer to an array describing the rpc methods supported by this object, terminated by either RPC_METHOD_END or RPC_METHOD_SUPER(Superclass).
|
|
| void | register_object (const char *name) |
|
Registers this object with the given name, so that it can be looked up with lookup.
|
|
| const char * | name () |
|
Returns the name of the object.
|
|
| virtual bool | rpc (const char *method, const char *arguments, char *result) |
|
Call the given method with the given arguments, and write the result into the string pointed to by result.
|
|
Static Public Member Functions |
|
| static bool | rpc (const char *name, const char *method, const char *arguments, char *result) |
|
Use the lookup function to lookup an object and, if successful, call its rpc method.
|
|
| static Base * | lookup (const char *name, unsigned int len) |
|
Lookup and return the object that has the given name.
|
|
| template<class C > | |
| static void | add_rpc_class () |
|
Add the class to the list of classes which can have static methods called via rpc (the static methods which can be called are defined by that class' get_rpc_class() static method).
|
|
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 enable(p5);
DigitalOut led(LED1);
int main() {
while(enable) {
led = !led;
wait(0.25);
}
}
Related¶
To handle an interrupt, see InterruptIn