Serial Communication
Dependencies: mbed
Fork of Nucleo_serial_menu by
Diff: main.cpp
- Revision:
- 10:af00e881b81e
- Parent:
- 9:6992eccf476e
diff -r 6992eccf476e -r af00e881b81e main.cpp --- a/main.cpp Fri Oct 20 03:12:39 2017 +0000 +++ b/main.cpp Fri Nov 03 08:57:11 2017 +0000 @@ -5,10 +5,187 @@ // 9600 bauds, 8-bit data, no parity //------------------------------------ -Serial pc(D8, D2); +Serial pc(D1, D0); +DigitalIn sw1(D11), sw2(D12), sw3(D13); +DigitalOut led_0(D2), led_1(D3), led_2(D4), led_3(D5), led_4(D7), led_5(D8), led_6(D9), led_7(D10); +int main() +{ + + uint8_t state_menu=0; + uint8_t state_show=0; + uint8_t state_exit =0; + uint8_t data; + + //myled = 0; + pc.readable(); + pc.printf("Hello World !\n\n"); + while(1) { + if(state_show == 0) { + pc.printf("************\n"); + pc.printf(" Menu \n"); + pc.printf("************\n"); + pc.printf("1.LED Function\n"); + pc.printf("2.Read DigitalIn\n"); + state_show =1; + } + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_show =0; + state_exit =0; + + switch(data) { + case '1': + do { + if(state_menu == 0) { + pc.printf("LED Test\n"); + pc.printf("a.LED Pattern_1\n"); + pc.printf("d.LED Pattern_2\n"); + pc.printf("s.Exit\n"); + state_menu = 1; + } + + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_menu=0; + + switch(data) { + + case 'a': + while(data=='a'){ + led_7 = 1; + wait(0.05); + led_7 = 0; + led_6 = 1; + wait(0.05); + led_6 = 0; + led_5 = 1; + wait(0.05); + led_5 = 0; + led_4 = 1; + wait(0.05); + led_4 = 0; + led_3 = 1; + wait(0.05); + led_3 = 0; + led_2 = 1; + wait(0.05); + led_2 = 0; + led_1 = 1; + wait(0.05); + led_1 = 0; + led_0 = 1; + wait(0.05); + led_0 = 0; + if(pc.readable()) { + data = pc.getc(); + if (data=='s'){ + break; + } + } + } + //break; -DigitalOut myled(LED1); + case 'd': + while(data=='d'){ + led_0 = 1; + wait(0.05); + led_0 = 0; + led_1 = 1; + wait(0.05); + led_1 = 0; + led_2 = 1; + wait(0.05); + led_2 = 0; + led_3 = 1; + wait(0.05); + led_3 = 0; + led_4 = 1; + wait(0.05); + led_4 = 0; + led_5 = 1; + wait(0.05); + led_5 = 0; + led_6 = 1; + wait(0.05); + led_6 = 0; + led_7 = 1; + wait(0.05); + led_7 = 0; + if(pc.readable()) { + data = pc.getc(); + if (data=='s'){ + break; + } + } + } + //break; + + case 's': + state_exit =1; + + break; + default: + pc.printf("plz select a or d or s\n"); + pc.printf("\n\n"); + break; + } + } + } while(state_exit ==0); + + pc.printf("\n"); + break; + + case '2': + + do { + if(state_menu == 0) { + pc.printf("Showing 3 DigitalIn Val\n"); + state_menu = 1; + } + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_menu=0; + + switch(data) { + + case 'a': + pc.printf("sw1: %d ", sw1.read()); + pc.printf("sw2: %d ", sw2.read()); + pc.printf("sw3: %d \n", sw3.read()); + break; + + + case 's': + state_exit =1; + + + break; + + default: + pc.printf("plz select a or s\n"); + pc.printf("\n"); + break; + + } + } + } while(state_exit ==0); + pc.printf("\n"); + break; + + + default: + pc.printf("plz select 1 or 2 \n"); + pc.printf("\n"); + break; + } + } + } +} +/* int main() { @@ -129,4 +306,4 @@ } } } -} +}*/