starting hello world program

Dependencies:   mbed

Committer:
tsbiberdorf
Date:
Sat Dec 01 22:20:02 2018 +0000
Revision:
0:d333b594399c
starting hello world program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsbiberdorf 0:d333b594399c 1 #include "mbed.h"
tsbiberdorf 0:d333b594399c 2
tsbiberdorf 0:d333b594399c 3 DigitalOut led_red(LED_RED);
tsbiberdorf 0:d333b594399c 4 DigitalOut led_green(LED_GREEN);
tsbiberdorf 0:d333b594399c 5 DigitalIn sw2(SW2);
tsbiberdorf 0:d333b594399c 6 DigitalIn sw3(SW3);
tsbiberdorf 0:d333b594399c 7 Serial pc(USBTX, USBRX);
tsbiberdorf 0:d333b594399c 8
tsbiberdorf 0:d333b594399c 9 void check_sw2(void)
tsbiberdorf 0:d333b594399c 10 {
tsbiberdorf 0:d333b594399c 11 if (sw2 == 0) {
tsbiberdorf 0:d333b594399c 12 pc.printf("SW2 button pressed. \n");
tsbiberdorf 0:d333b594399c 13 led_red = 0;
tsbiberdorf 0:d333b594399c 14 led_green = 1;
tsbiberdorf 0:d333b594399c 15 }
tsbiberdorf 0:d333b594399c 16 }
tsbiberdorf 0:d333b594399c 17
tsbiberdorf 0:d333b594399c 18 void check_sw3(void)
tsbiberdorf 0:d333b594399c 19 {
tsbiberdorf 0:d333b594399c 20 if (sw3 == 0) {
tsbiberdorf 0:d333b594399c 21 pc.printf("SW3 button pressed. \n");
tsbiberdorf 0:d333b594399c 22 led_green = 0;
tsbiberdorf 0:d333b594399c 23 led_red = 1;
tsbiberdorf 0:d333b594399c 24 pc.printf("5 characters will be echoed. Start typing. \n");
tsbiberdorf 0:d333b594399c 25 for (uint32_t i = 0; i < 5; i++) {
tsbiberdorf 0:d333b594399c 26 pc.putc(pc.getc());
tsbiberdorf 0:d333b594399c 27 }
tsbiberdorf 0:d333b594399c 28 pc.putc(13); /* CR */
tsbiberdorf 0:d333b594399c 29 pc.putc(10); /* LF */
tsbiberdorf 0:d333b594399c 30 }
tsbiberdorf 0:d333b594399c 31 }
tsbiberdorf 0:d333b594399c 32
tsbiberdorf 0:d333b594399c 33 int main() {
tsbiberdorf 0:d333b594399c 34 led_green = 1;
tsbiberdorf 0:d333b594399c 35 led_red = 1;
tsbiberdorf 0:d333b594399c 36 pc.baud(115200);
tsbiberdorf 0:d333b594399c 37 pc.printf("Hello World from FRDM-K64F board.\n");
tsbiberdorf 0:d333b594399c 38
tsbiberdorf 0:d333b594399c 39 while (true) {
tsbiberdorf 0:d333b594399c 40 check_sw2();
tsbiberdorf 0:d333b594399c 41 check_sw3();
tsbiberdorf 0:d333b594399c 42 wait(0.3);
tsbiberdorf 0:d333b594399c 43 }
tsbiberdorf 0:d333b594399c 44 }