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.
main.cpp@1:fdb8ecdf954f, 2017-03-15 (annotated)
- Committer:
- CSTritt
- Date:
- Wed Mar 15 01:54:31 2017 +0000
- Revision:
- 1:fdb8ecdf954f
- Parent:
- 0:8d318218bac1
- Child:
- 2:f91fc3b8d8f7
Demonstrates serial communications and digital output. Initial version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mab5449 | 0:8d318218bac1 | 1 | #include "mbed.h" |
CSTritt | 1:fdb8ecdf954f | 2 | /* |
CSTritt | 1:fdb8ecdf954f | 3 | Serial2RGB main by C. S. Tritt, Last revised 3/14/17 (v. 1.0) |
CSTritt | 1:fdb8ecdf954f | 4 | Toggles RGB LED junctions in response to serial input. Uses "unbuffered" |
CSTritt | 1:fdb8ecdf954f | 5 | reads (Enter, CR/LF not required). |
CSTritt | 1:fdb8ecdf954f | 6 | */ |
CSTritt | 1:fdb8ecdf954f | 7 | DigitalOut RedLED(D9); // Physically same as Arduino Digital pin 9. |
CSTritt | 1:fdb8ecdf954f | 8 | DigitalOut GrnLED(D10); // Physically same as Arduino Digital pin 10. |
CSTritt | 1:fdb8ecdf954f | 9 | DigitalOut BluLED(D11); // Physically same as Arduino Digital pin 11. |
CSTritt | 1:fdb8ecdf954f | 10 | |
CSTritt | 1:fdb8ecdf954f | 11 | Serial pc(USBTX, USBRX); // Default settings are 9600 Baud, 8-N-1. |
mab5449 | 0:8d318218bac1 | 12 | |
mab5449 | 0:8d318218bac1 | 13 | int main() { |
CSTritt | 1:fdb8ecdf954f | 14 | |
CSTritt | 1:fdb8ecdf954f | 15 | RedLED = 0; |
CSTritt | 1:fdb8ecdf954f | 16 | GrnLED = 0; |
CSTritt | 1:fdb8ecdf954f | 17 | BluLED = 0; |
CSTritt | 1:fdb8ecdf954f | 18 | char letter; |
CSTritt | 1:fdb8ecdf954f | 19 | |
mab5449 | 0:8d318218bac1 | 20 | while(1) { |
CSTritt | 1:fdb8ecdf954f | 21 | if (pc.readable()) { |
CSTritt | 1:fdb8ecdf954f | 22 | letter = pc.getc(); |
CSTritt | 1:fdb8ecdf954f | 23 | pc.putc(letter); |
CSTritt | 1:fdb8ecdf954f | 24 | if (letter == 'r') { |
CSTritt | 1:fdb8ecdf954f | 25 | RedLED = !RedLED; |
CSTritt | 1:fdb8ecdf954f | 26 | } |
CSTritt | 1:fdb8ecdf954f | 27 | else if (letter == 'g') { |
CSTritt | 1:fdb8ecdf954f | 28 | GrnLED = !GrnLED; |
CSTritt | 1:fdb8ecdf954f | 29 | } |
CSTritt | 1:fdb8ecdf954f | 30 | else if (letter == 'b') { |
CSTritt | 1:fdb8ecdf954f | 31 | BluLED = !BluLED; |
CSTritt | 1:fdb8ecdf954f | 32 | } |
mab5449 | 0:8d318218bac1 | 33 | } |
mab5449 | 0:8d318218bac1 | 34 | } |
mab5449 | 0:8d318218bac1 | 35 | } |