Charles Tritt / Mbed 2 deprecated SerialEcho

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* 
00002     Project: SerialEcho
00003     File: main.cpp
00004     Created by: Dr. C. S. Tritt
00005     Last revised: 1/17/19 (v. 1.0)
00006     
00007     Receives serial data from PC to and echos it back, character for character.
00008     
00009     Tera Term configurations
00010     Terminal - New-line, Receive LF, Transmit LF
00011     Serial port - Data 8 bit, Parity none, Stop 1 bit, Flow control none.
00012     Baud as specified below.
00013 */
00014 #include "mbed.h"
00015 
00016 Serial pc(USBTX, USBRX, 9600); // Standard to PC via USB channel.
00017 
00018 DigitalOut actLED(LED1); // Activity LED.
00019 
00020 int main()
00021 {
00022     while (true) {
00023         if (pc.readable()) {
00024             char character = (char) pc.getc(); // Get a char from the PC.
00025             pc.putc(character); // Send it back to the PC.
00026             actLED = !actLED; // Toggle the activity LED.
00027         }
00028     }
00029 }