Array of DigitalOut Objects
Page last updated 05 Nov 2010, by .
2 replies
Simple array of DigitalOut objects initialized in the declaration. Primarily for demonstration and for getting accustomed to this compiler and user interface.
#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);
}
}
}
2 comments
#
05 Nov 2010
#
05 Nov 2010
Please log in to post a comment.


Note that you can use BusOut class to achieve similar functionality. Also, you don't need parentheses around LEDn constants.