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
- Committer:
- CSTritt
- Date:
- 2017-09-12
- Revision:
- 5:c849e3c4a5f0
- Parent:
- 4:43ce9b92ae68
- Child:
- 6:dcc4031025a6
File content as of revision 5:c849e3c4a5f0:
#include "mbed.h" /* Serial2RGB main by C. S. Tritt, Last revised 9/12/17 (v. 1.2) Toggles RGB LED junctions in response to serial input. Note input is case sensive and known "commands" are r (toggle red), g (toggle green) and b toggle blue). Input (including CR/LF is echoed. Suggested wiring... Common Anode LED (active low) /-- 680 kΩ -- D13 (red) + 3.3 to 5.0 V ----LED<--- 680 Ω -- D14 (green) \-- 1 kΩ -- D15 (blue) Common Cathode LED (active high) /-- 680 Ω -- D13 (red) GND ----LED<--- 680 Ω -- D14 (green) \-- 1 kΩ -- D15 (blue) */ // Construct resources. DigitalOut RedLED(D13); // Arduino Digital pin 13 on Nucleos. DigitalOut GrnLED(D14); // Arduino Digital pin 14. DigitalOut BluLED(D15); // Arduino Digital pin 15. Serial pc(USBTX, USBRX); // Default settings are 9600 Baud, 8-N-1. int main() { RedLED = 0; // Set pins to known state (junction on if active low). GrnLED = 0; BluLED = 0; char letter; // Declare variable to hold recieved characters. while(true) { // Main (infinite) loop. if (pc.readable()) { // Is there a character waiting? If so, letter = pc.getc(); // Get it. pc.putc(letter); // Echo it. if (letter == 'r') { // Respond to known letters, ignore others. RedLED = !RedLED; // Toggle red. } else if (letter == 'g') { GrnLED = !GrnLED; // Toggle green. } else if (letter == 'b') { BluLED = !BluLED; // Toggle blue. } } } }