This is single way communication with the PC

Dependencies:   mbed

Committer:
RahulSitaram
Date:
Sun Dec 04 19:19:19 2016 +0000
Revision:
0:5d7b0ed9dcc9
Child:
1:dad12410fd2d
This is one way serial communication to PC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RahulSitaram 0:5d7b0ed9dcc9 1 #include "mbed.h"
RahulSitaram 0:5d7b0ed9dcc9 2
RahulSitaram 0:5d7b0ed9dcc9 3 DigitalOut led1(LED1);
RahulSitaram 0:5d7b0ed9dcc9 4 DigitalOut led2(LED2);
RahulSitaram 0:5d7b0ed9dcc9 5 uint8_t data;
RahulSitaram 0:5d7b0ed9dcc9 6 Serial pc(USBTX, USBRX);
RahulSitaram 0:5d7b0ed9dcc9 7
RahulSitaram 0:5d7b0ed9dcc9 8 void call() {
RahulSitaram 0:5d7b0ed9dcc9 9 // Note: you need to actually read from the serial to clear the RX interrupt
RahulSitaram 0:5d7b0ed9dcc9 10 data = pc.getc();
RahulSitaram 0:5d7b0ed9dcc9 11 printf("%c\n", data);
RahulSitaram 0:5d7b0ed9dcc9 12 led2 = !led2;
RahulSitaram 0:5d7b0ed9dcc9 13 }
RahulSitaram 0:5d7b0ed9dcc9 14
RahulSitaram 0:5d7b0ed9dcc9 15 int main() {
RahulSitaram 0:5d7b0ed9dcc9 16 pc.attach(&call);
RahulSitaram 0:5d7b0ed9dcc9 17 while (1) {
RahulSitaram 0:5d7b0ed9dcc9 18 led1 = !led1;
RahulSitaram 0:5d7b0ed9dcc9 19 wait(0.5);
RahulSitaram 0:5d7b0ed9dcc9 20 }
RahulSitaram 0:5d7b0ed9dcc9 21 }