Jasper Lee / twr_helloworld

Dependencies:   mbed_helloworld

Fork of frdm_helloworld by Freescale

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut led_red(LED_RED);
00004 DigitalOut led_green(LED_GREEN);
00005 DigitalIn sw2(SW2);
00006 DigitalIn sw3(SW3);
00007 Serial pc(USBTX, USBRX);
00008 char  str[6];
00009 uint32_t i;
00010 void check_sw2(void)
00011 {
00012     if (sw2 == 0) {
00013         pc.printf("SW2 button pressed. \n");
00014         led_red = 0;
00015         led_green = 1;
00016     }
00017 }
00018 
00019 void check_sw3(void)
00020 {
00021     if (sw3 == 0) {
00022         pc.printf("SW3 button pressed. \n");
00023         led_green = 0;
00024         led_red = 1;
00025         pc.printf("5 characters will be echoed. Start typing. \n");
00026         for ( i = 0; i < 5; i++) {
00027             str[i] = pc.getc();
00028   //          pc.putc(pc.getc());
00029         }
00030         str[i] ='\0';
00031         pc.puts(str);
00032         pc.putc(13); /* CR */
00033         pc.putc(10); /* LF */
00034         pc.printf("Test Finished \n");
00035     }
00036 }
00037 
00038 int main() {
00039     led_green = 1;
00040     led_red = 1;
00041     pc.baud(115200);
00042     pc.printf("Hello World from FRDM-K64F board.\n");
00043 
00044     while (true) {
00045         check_sw2();
00046         check_sw3();
00047         wait(0.3);
00048     }
00049 }