The DigitalOut interface is used to configure and control a digital output pin.
Hello World!
Flash an LED
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.25);
myled = 0;
wait(0.25);
}
}
API
API summary
Interface
The DigitalOut Interface can be used on mbed pins p5-p30, and also on-board LED1-LED4
The DigitalOut Interface can be used to set the state of the output pin, and also read back the current output state. Set the DigitalOut to zero to turn it off, or 1 to turn it on.
Details
The pin output is 0v and 3.3v (0 and 1), and can source or sink a maximum of 40mA.
Examples
Alternative flashing
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = !myled;
wait(0.25);
}
}
Alternative flashing
#include "mbed.h"
DigitalOut red(p5);
DigitalOut green(p6);
DigitalOut blue(p7);
int main() {
// red
red = 1;
green = blue = 0;
wait(1);
// green
green = 1;
red = blue = 0;
wait(1);
// white
red = green = blue = 1;
}
Last modified 21 Jul 2010, by
Dan Ros

No tags
|
15 comments
Just for fun, here's a "chase" program that shows how to use an array of DigitalOut objects to control the onboard LEDs for the LPC1768 contest board:
Code
#include "mbed.h" DigitalOut leds[] = {(LED1), (LED2),(LED3)}; int main() { int i, previous; int numLeds = sizeof(leds)/sizeof(DigitalOut); while(1) { for (i = 0; i < numLeds; i++){ if (i == 0) previous = (numLeds - 1); else previous = i - 1; leds[i] = 1; leds[previous] = 0; wait(0.2); } } }