tower 120

Dependencies:   mbed_helloworld

Fork of frdm_helloworld by Freescale

Committer:
Jasper_lee
Date:
Tue Dec 23 06:25:48 2014 +0000
Revision:
4:b851b9236d1a
Parent:
3:3eac3aecc889
change some test code

Who changed what in which revision?

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