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