l
Dependencies: mbed
Fork of Nucleo_serial_sf by
Revision 4:eae42fe39107, committed 2015-10-26
- Comitter:
- NamSom
- Date:
- Mon Oct 26 09:48:51 2015 +0000
- Parent:
- 3:a46061896235
- Commit message:
- 55
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a46061896235 -r eae42fe39107 main.cpp --- a/main.cpp Mon Oct 26 03:32:41 2015 +0000 +++ b/main.cpp Mon Oct 26 09:48:51 2015 +0000 @@ -1,10 +1,12 @@ -#include "mbed.h" + #include "mbed.h" //------------------------------------ // Hyperterminal configuration // 9600 bauds, 8-bit data, no parity //------------------------------------ - +int pattern1(); +int pattern2(); +int checkState(); Serial pc(SERIAL_TX, SERIAL_RX); DigitalOut myled0(D15); @@ -17,73 +19,76 @@ DigitalOut myled7(D8); DigitalIn inbutton(D3); +char data; int checkState() { + if(pc.readable()==1){ data = pc.getc(); - if(data=='s'||data='S') return 1; - else if(data=='a'||data='A') return 2; - else (data=='d'||data='D') return 3; - else return 0; + if(data=='s'||data=='S') {return 1;} + else if(data=='a'||data=='A') {return 2;} + else if(data=='d'||data=='D') {return 3;} + else return 0;} } -void pattern1() +int pattern1() { - uint8_t check; + int check; while(1){ myled0=1; wait(1); myled0=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled1=1; wait(1); myled1=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled2=1; wait(1); myled2=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled3=1; wait(1); myled3=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled4=1; wait(1); myled4=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled5=1; wait(1); myled5=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled6=1; wait(1); myled6=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled7=1; wait(1); myled7=0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; } pattern2(); + return 0; } -void pattern2() +int pattern2() { uint8_t check; while(1) { @@ -97,7 +102,7 @@ myled4 =0; myled5 =0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; myled2 =1; myled3 =1; @@ -109,10 +114,11 @@ myled6 =0; myled7 =0; check=checkState(); - if(check==1) return 1; + if(check==1) {return 1;} else if(check==3) break; } pattern1(); + return 0; } @@ -123,8 +129,7 @@ uint8_t state_show=0; uint8_t state_exit =0; uint8_t state_LED =0; - uint8_t data; - + myled0 = 0; myled1 = 0; myled2 = 0; @@ -162,7 +167,7 @@ pc.printf("\n"); state_menu=0; - if(data=='a'||data='A') { + if(data=='a'||data=='A') { pattern1(); } if(data=='d'||data=='D') {