OK. That works. Here’s the full version of the code, updated with the BusOut syntax:
#include "mbed.h"
#include "USBSerial.h"
//Virtual serial port over USB
USBSerial serial;
BusOut LED(LED1, LED2, LED3, LED4, LED5, LED6, LED7);
float delayTime = .05;
void debugOutput ( int x )
{
switch (x)
{
case 0:
case 6:
serial.printf("Red!\r\n");
break;
case 1:
case 5:
serial.printf("Orange!\r\n");
break;
case 2:
case 4:
serial.printf("Yellow!\r\n");
break;
case 3:
serial.printf("Green!\r\n");
break;
default:
serial.printf("Not an LED!\r\n");
break;
}
return;
}
int main()
{
while(1)
{
delayTime = 0.25;
for(int x = 0; x < 7; x++)
{
debugOutput ( x );
LED = LED | (1<<x); // turn on
wait(.2); // delay
LED = LED & ~(1<<x); // turn off
wait(delayTime); // delay
}
for(int x = 5; x >= 0; x--)
{
debugOutput ( x );
LED = LED | (1<<x); // turn on
wait(.2); // delay
LED = LED & ~(1<<x); // turn off
wait(delayTime); // delay
}
for(int x = 0; x < 7; x++)
{
debugOutput ( x );
LED = LED | (1<<x); // turn on
wait(delayTime); // delay
}
for(int x = 6; x >= 0; x--)
{
debugOutput ( x );
LED = LED & ~(1<<x); // turn off
wait(delayTime); // delay
}
}
}
Nope. I was working purely off the mbed.org instructions. If USBRX/TX aren’t connected - then that’s a pretty big misdirection. I’ll have to invest in a usb-serial plug - I really wanted the least fussy solution which would be to use a standard micro-usb cable.
Don’t forget that most converters will want rs232 levels not logic levels.
You can get logic level converter cables (USB TTL Serial Cable Series - FTDI ) or in past I’ve cracked open a normal one and bypassed the level shifting chip.