xiao sun
/
frdm_helloworld
first try
main.cpp@0:894a728148ef, 2015-01-17 (annotated)
- Committer:
- sunsmile2015
- Date:
- Sat Jan 17 16:08:06 2015 +0000
- Revision:
- 0:894a728148ef
hello mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunsmile2015 | 0:894a728148ef | 1 | #include "mbed.h" |
sunsmile2015 | 0:894a728148ef | 2 | |
sunsmile2015 | 0:894a728148ef | 3 | DigitalOut led_red(LED_RED); |
sunsmile2015 | 0:894a728148ef | 4 | DigitalOut led_green(LED_GREEN); |
sunsmile2015 | 0:894a728148ef | 5 | DigitalIn sw2(SW2); |
sunsmile2015 | 0:894a728148ef | 6 | DigitalIn sw3(SW3); |
sunsmile2015 | 0:894a728148ef | 7 | Serial pc(USBTX, USBRX); |
sunsmile2015 | 0:894a728148ef | 8 | |
sunsmile2015 | 0:894a728148ef | 9 | void check_sw2(void) |
sunsmile2015 | 0:894a728148ef | 10 | { |
sunsmile2015 | 0:894a728148ef | 11 | if (sw2 == 0) { |
sunsmile2015 | 0:894a728148ef | 12 | pc.printf("SW2 button pressed. \n"); |
sunsmile2015 | 0:894a728148ef | 13 | led_red = 0; |
sunsmile2015 | 0:894a728148ef | 14 | led_green = 1; |
sunsmile2015 | 0:894a728148ef | 15 | } |
sunsmile2015 | 0:894a728148ef | 16 | } |
sunsmile2015 | 0:894a728148ef | 17 | |
sunsmile2015 | 0:894a728148ef | 18 | void check_sw3(void) |
sunsmile2015 | 0:894a728148ef | 19 | { |
sunsmile2015 | 0:894a728148ef | 20 | if (sw3 == 0) { |
sunsmile2015 | 0:894a728148ef | 21 | pc.printf("SW3 button pressed. \n"); |
sunsmile2015 | 0:894a728148ef | 22 | led_green = 0; |
sunsmile2015 | 0:894a728148ef | 23 | led_red = 1; |
sunsmile2015 | 0:894a728148ef | 24 | pc.printf("5 characters will be echoed. Start typing. \n"); |
sunsmile2015 | 0:894a728148ef | 25 | for (uint32_t i = 0; i < 5; i++) { |
sunsmile2015 | 0:894a728148ef | 26 | pc.putc(pc.getc()); |
sunsmile2015 | 0:894a728148ef | 27 | } |
sunsmile2015 | 0:894a728148ef | 28 | pc.putc(13); /* CR */ |
sunsmile2015 | 0:894a728148ef | 29 | pc.putc(10); /* LF */ |
sunsmile2015 | 0:894a728148ef | 30 | } |
sunsmile2015 | 0:894a728148ef | 31 | } |
sunsmile2015 | 0:894a728148ef | 32 | |
sunsmile2015 | 0:894a728148ef | 33 | int main() { |
sunsmile2015 | 0:894a728148ef | 34 | led_green = 1; |
sunsmile2015 | 0:894a728148ef | 35 | led_red = 1; |
sunsmile2015 | 0:894a728148ef | 36 | pc.baud(115200); |
sunsmile2015 | 0:894a728148ef | 37 | pc.printf("Hello mbed from Xiao's FRDM-K64F board.\n"); |
sunsmile2015 | 0:894a728148ef | 38 | |
sunsmile2015 | 0:894a728148ef | 39 | while (true) { |
sunsmile2015 | 0:894a728148ef | 40 | check_sw2(); |
sunsmile2015 | 0:894a728148ef | 41 | check_sw3(); |
sunsmile2015 | 0:894a728148ef | 42 | wait(0.3); |
sunsmile2015 | 0:894a728148ef | 43 | } |
sunsmile2015 | 0:894a728148ef | 44 | } |