Serial_command
Dependencies: mbed
Revision 0:6ed167046340, committed 2015-11-16
- Comitter:
- NorNick
- Date:
- Mon Nov 16 17:03:38 2015 +0000
- Commit message:
- Finish
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 16 17:03:38 2015 +0000 @@ -0,0 +1,184 @@ +#include "mbed.h" + +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + +Serial pc(SERIAL_TX, SERIAL_RX); + +//Serial pc(D8, D2); + +DigitalIn Sw(D3); + +BusOut ledSet(D4, D9, D5, D11, D12, D13, D14, D15); + +Timer t; + +int main() +{ + + uint8_t state_menu=0; + uint8_t state_show=0; + uint8_t state_exit =0; + uint8_t data; + int timer_delay1=200,timer_delay2=400,timer_delay3=600,timer_delay4=800; + t.start(); + ledSet = 0; + pc.printf("Hello Nucleo !\n"); + while(1) { + if(state_show == 0) { + pc.printf("Menu\n"); + pc.printf("1.LED Test\n"); + pc.printf("2.Switch Test\n"); + state_show =1; + } + if(pc.readable()) { + data = pc.getc(); + pc.printf("\n"); + state_show =0; + state_exit =0; + + switch(data) { + case '1': + /*Bew Style*/ + do { + if(state_menu == 0) { + pc.printf("LED Test\n"); + pc.printf("a.LED ModeI\n"); + pc.printf("d.LED ModeII\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': + pc.printf("LED ModeI ON.\n"); + pc.printf("LED Test\n"); + pc.printf("a.LED ModeI\n"); + pc.printf("d.LED ModeII\n"); + pc.printf("s.Exit\n"); + while(1){ + if(pc.readable()==0){ + if(t.read_ms() <timer_delay1) { + ledSet = 0xAA; + } else if(t.read_ms() <timer_delay2) { + ledSet = 0x55; + } else { + t.reset(); + } + } + else{ + break; + } + } + + break; + + case 'd': + pc.printf("LED ModeII ON.\n"); + pc.printf("LED Test\n"); + pc.printf("a.LED ModeI\n"); + pc.printf("d.LED ModeII\n"); + pc.printf("s.Exit\n"); + while(1){ + if(pc.readable()==0){ + if(t.read_ms() <timer_delay1) { + ledSet = 0xF0; + } else if(t.read_ms() <timer_delay2) { + ledSet = 0x0F; + } else if(t.read_ms() <timer_delay3) { + ledSet = 0xCC; + } else if(t.read_ms() <timer_delay4) { + ledSet = 0x33; + }else { + t.reset(); + } + } + else{ + break; + } + } + break; + + case 's': + ledSet = 0x00; + state_menu=0; + state_exit =1; + pc.printf("Exit..... \n"); + + + break; + + default: + pc.printf("plz select a or s\n"); + pc.printf("\n\n"); + break; + + } + } + + } while(state_exit ==0); + pc.printf("\n\n"); + break; + + case '2': + + do { + if(state_menu == 0) { + pc.printf("Switch Test\n"); + pc.printf("a.Read Switch\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': + + pc.printf("Status :: %d \n",Sw.read()); + + break; + + case 's': + state_exit =1; + + + break; + + default: + pc.printf("plz select a or x\n"); + pc.printf("\n\n"); + break; + + } + } + + } while(state_exit ==0); + pc.printf("\n\n"); + break; + + + case 0x00: + + break; + + default: + pc.printf("plz select 1 or 2 only\n"); + pc.printf("\n\n"); + break; + } + } + + + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Nov 16 17:03:38 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file