EXP6

Dependencies:   mbed

Committer:
rx5
Date:
Wed Apr 13 05:37:46 2016 +0000
Revision:
0:6559b3e93bca
EXP6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rx5 0:6559b3e93bca 1 #include "mbed.h"
rx5 0:6559b3e93bca 2 DigitalOut myledr(LED_RED); // initlize RED LED pin as OUTPUT
rx5 0:6559b3e93bca 3 DigitalOut myledg(LED_GREEN); // initlize GREEN LED pin as OUTPUT
rx5 0:6559b3e93bca 4 DigitalOut myledb(LED_BLUE); // initlize BLUE LED pin as OUTPUT
rx5 0:6559b3e93bca 5 Serial pc(USBTX, USBRX); // Initlize UART on USB port of KL25Z with default Baud 9600
rx5 0:6559b3e93bca 6
rx5 0:6559b3e93bca 7 void showhelp()
rx5 0:6559b3e93bca 8 {
rx5 0:6559b3e93bca 9 pc.printf("\r\n"); // print Command list from new line on UART Terminal
rx5 0:6559b3e93bca 10 pc.printf("**** Command List ****\r\n"); // print Command list on UART Terminal
rx5 0:6559b3e93bca 11 pc.printf("h -> Help\r\n");
rx5 0:6559b3e93bca 12 pc.printf("r -> Turn on RED LED\r\n");
rx5 0:6559b3e93bca 13 pc.printf("R -> Turn off RED LED\r\n");
rx5 0:6559b3e93bca 14 pc.printf("g -> Turn on GREEN LED\r\n");
rx5 0:6559b3e93bca 15 pc.printf("G -> Turn off GREEN LED\r\n");
rx5 0:6559b3e93bca 16 pc.printf("b -> Turn on BLUE LED\r\n");
rx5 0:6559b3e93bca 17 pc.printf("B -> Turn off BLUE LED\r\n");
rx5 0:6559b3e93bca 18 }
rx5 0:6559b3e93bca 19
rx5 0:6559b3e93bca 20 int main()
rx5 0:6559b3e93bca 21 {
rx5 0:6559b3e93bca 22 char rxbyte;
rx5 0:6559b3e93bca 23 // pc.baud(115200); // uncomment this line and update baudrate to cahnge baud rate from 9600 default
rx5 0:6559b3e93bca 24 myledr = 1; // Turn Off RED LED
rx5 0:6559b3e93bca 25 myledg = 1; // Turn Off GREEN LED
rx5 0:6559b3e93bca 26 myledb = 1; // Turn Off BLUE LED
rx5 0:6559b3e93bca 27 pc.printf("\r\n"); // print startup message from new line on UART Terminal
rx5 0:6559b3e93bca 28 pc.printf("Experiment - 6\r\n"); // print startup message on UART Terminal
rx5 0:6559b3e93bca 29 pc.printf("UART Interfacing TX RX \r\n"); // print startup message on UART Terminal
rx5 0:6559b3e93bca 30 pc.printf("\r\n"); // print startup message from new line on UART Terminal
rx5 0:6559b3e93bca 31 showhelp();
rx5 0:6559b3e93bca 32 wait(3.0); // wait 3 second to show startup message
rx5 0:6559b3e93bca 33 while (true)
rx5 0:6559b3e93bca 34 {
rx5 0:6559b3e93bca 35 wait(0.5f); // wait a small period of time
rx5 0:6559b3e93bca 36 if (pc.readable())
rx5 0:6559b3e93bca 37 { // If pc is readable
rx5 0:6559b3e93bca 38 rxbyte = pc.getc();
rx5 0:6559b3e93bca 39 if(rxbyte == 'r') {pc.printf("RED LED ON\r\n"); myledr = 0;}
rx5 0:6559b3e93bca 40 else if(rxbyte == 'R') {pc.printf("RED LED OFF\r\n"); myledr = 1;}
rx5 0:6559b3e93bca 41 else if(rxbyte == 'g') {pc.printf("RED LED ON\r\n"); myledg = 0;}
rx5 0:6559b3e93bca 42 else if(rxbyte == 'G') {pc.printf("RED LED OFF\r\n"); myledg = 1;}
rx5 0:6559b3e93bca 43 else if(rxbyte == 'b') {pc.printf("RED LED ON\r\n"); myledb = 0;}
rx5 0:6559b3e93bca 44 else if(rxbyte == 'B') {pc.printf("RED LED OFF\r\n"); myledb = 1;}
rx5 0:6559b3e93bca 45 else if(rxbyte == 'h') {showhelp();}
rx5 0:6559b3e93bca 46 else {pc.printf("Error: Invalid command type 'h' for help...\r\n"); }
rx5 0:6559b3e93bca 47 rxbyte = 0x00;
rx5 0:6559b3e93bca 48 }
rx5 0:6559b3e93bca 49
rx5 0:6559b3e93bca 50 }
rx5 0:6559b3e93bca 51 }
rx5 0:6559b3e93bca 52