Serial Communication
Dependencies: mbed
Fork of Nucleo_serial_menu by
Diff: main.cpp
- Revision:
- 1:df3b700ba2d9
- Parent:
- 0:f4e546303b4e
- Child:
- 2:87127bdc7e93
diff -r f4e546303b4e -r df3b700ba2d9 main.cpp --- a/main.cpp Sun Oct 18 10:09:46 2015 +0000 +++ b/main.cpp Tue Oct 20 08:20:13 2015 +0000 @@ -6,8 +6,11 @@ //------------------------------------ Serial pc(SERIAL_TX, SERIAL_RX); - +DigitalOut led[] = {D2,D3,D4,D5,D6,D7,D8,D9}; DigitalOut myled(LED1); +DigitalIn sw(D0); +double speed=0.1; +int pat = 1,tog=0; int main() { @@ -37,9 +40,10 @@ do { if(state_menu == 0) { pc.printf("LED Test\n"); - pc.printf("a.LED ON\n"); - pc.printf("s.LED OFF\n"); - pc.printf("x.Exit\n"); + pc.printf("a.LED Pattern1\n"); + pc.printf("d.LED Pattern2\n"); + + pc.printf("s.Exit\n"); state_menu = 1; } if(pc.readable()) { @@ -50,22 +54,40 @@ switch(data) { case 'a': - myled = 1; + if(pat==1){ + for(int x=0;x<=7;x++){ + led[x]=1; + wait(speed); + led[x]=0; + + } + } + break; + + case 'd': + if(pat==2){ + for(int x=0;x<=7;x++){ + led[x]=1; + wait(speed); + + } + for(int x=0;x<=7;x++){ + led[x]=0; + wait(speed); + + } + + } break; case 's': - myled =0; - - break; - - case 'x': state_exit =1; break; default: - pc.printf("plz select a or s\n"); - pc.printf("\n\n"); + pc.printf("please select a or s\n"); + pc.printf("\n"); break; } @@ -87,40 +109,32 @@ pc.printf("x.Exit\n"); state_menu = 1; } - if(pc.readable()) { + if(sw.read()) { data = pc.getc(); pc.printf("\n"); state_menu=0; - - switch(data) { - - case 'a': - pc.printf("Menu 2 TEST\n"); - - break; - - case 's': - pc.printf("Run\n"); - - break; - - case 'x': - state_exit =1; - - - break; + myled = 1; + pc.putc(1); + } + + else + { myled = 0; + pc.putc(0); + } + + default: pc.printf("plz select a or s\n"); pc.printf("\n\n"); break; - } + } - } while(state_exit ==0); + while(state_exit ==0); pc.printf("\n\n"); break; @@ -129,10 +143,7 @@ break; - default: - pc.printf("plz select 1 or 2 only\n"); - pc.printf("\n\n"); - break; + } }