Thank you for your replies. Using OS X 10.6.7 and its Terminal. In Terminal I type in: screen /dev/tty.usbmodem* and Return. This brings up a window which can capture serial sent from mBED through the USB cable. However, if I quit Terminal, this no longer works until I unmount and remount the mBed device. Then I can use Serial as described in the Handbook.
#include "mbed.h"
DigitalOut leds[] = {LED1, LED2, LED3, LED4};
Serial pc(USBTX, USBRX);
int main() {
int numLeds = sizeof(leds)/sizeof(DigitalOut);
pc.printf("%d", sizeof(DigitalOut));
pc.printf("%d", sizeof(leds));
pc.printf("%d",numLeds);
}
Interestingly, sizeof(DigitalOut) always return 28 (bytes I'm now assuming). And sizeof(leds) will return 112, 84, 56, or 28, depending on the array, whether 4, 3, 2, or 1 element(s). I'm using %d as suggested in the printf to get decimal.
So numLeds does always come out correct for the LED chasing code, which works for 2, 3, or 4 of the built-in LEDs. The code from Jeff Bosch seems completely general so that it could chase as many external LEDs as one wished to hook up.
#include "mbed.h"
DigitalOut leds[] = {LED1,LED2, LED3, LED4};
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.1);
}
}
}
I tried the LED chase program by Jeff Bosch, posted last year.
I do not understand the use of sizeof(DigitalOut) in his code:
To me, it looks like we want numLeds to equal four since our array has four elements. So then I assume that sizeof(leds) returns 4 and sizeof(DigitalOut) returns 1.
But this is clearly not the case. With the division the code works and without it, it does not.
How can I determine what an expression like sizeof(DigitalOut) returns?