Hello world example program. This program exercises many of the peripherials including serial (prints hello world), as well as pushbutton and LED usage.

Dependencies:   mbed

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 
00009 void check_sw2(void)
00010 {
00011     if (sw2 == 0) {
00012         pc.printf("SW2 button pressed. \n");
00013         led_red = 0;
00014         led_green = 1;
00015     }
00016 }
00017 
00018 void check_sw3(void)
00019 {
00020     if (sw3 == 0) {
00021         pc.printf("SW3 button pressed. \n");
00022         led_green = 0;
00023         led_red = 1;
00024         pc.printf("5 characters will be echoed. Start typing. \n");
00025         for (uint32_t i = 0; i < 5; i++) {
00026             pc.putc(pc.getc());
00027         }
00028         pc.putc(13); /* CR */
00029         pc.putc(10); /* LF */
00030     }
00031 }
00032 
00033 int main() {
00034     led_green = 1;
00035     led_red = 1;
00036     pc.baud(115200);
00037     pc.printf("Hello World from FRDM-K64F board.\n");
00038 
00039     while (true) {
00040         check_sw2();
00041         check_sw3();
00042         wait(0.3);
00043     }
00044 }