Serial_command
Dependencies: mbed
main.cpp
- Committer:
- NorNick
- Date:
- 2015-11-16
- Revision:
- 0:6ed167046340
File content as of revision 0:6ed167046340:
#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; } } } }