Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:fdb8ecdf954f
- Parent:
- 0:8d318218bac1
- Child:
- 2:f91fc3b8d8f7
--- a/main.cpp Thu Jan 19 14:23:37 2017 -0600 +++ b/main.cpp Wed Mar 15 01:54:31 2017 +0000 @@ -1,15 +1,35 @@ #include "mbed.h" -//K64F -Serial pc(USBTX, USBRX); // tx, rx -Serial device(MBED_CONF_APP_UART1_TX, MBED_CONF_APP_UART1_RX); // tx, rx +/* + Serial2RGB main by C. S. Tritt, Last revised 3/14/17 (v. 1.0) + Toggles RGB LED junctions in response to serial input. Uses "unbuffered" + reads (Enter, CR/LF not required). +*/ +DigitalOut RedLED(D9); // Physically same as Arduino Digital pin 9. +DigitalOut GrnLED(D10); // Physically same as Arduino Digital pin 10. +DigitalOut BluLED(D11); // Physically same as Arduino Digital pin 11. + +Serial pc(USBTX, USBRX); // Default settings are 9600 Baud, 8-N-1. int main() { + + RedLED = 0; + GrnLED = 0; + BluLED = 0; + char letter; + while(1) { - if(pc.readable()) { - device.putc(pc.getc()); - } - if(device.readable()) { - pc.putc(device.getc()); + if (pc.readable()) { + letter = pc.getc(); + pc.putc(letter); + if (letter == 'r') { + RedLED = !RedLED; + } + else if (letter == 'g') { + GrnLED = !GrnLED; + } + else if (letter == 'b') { + BluLED = !BluLED; + } } } }