Serial Communication

Dependencies:   mbed

Fork of Nucleo_serial_menu by FRA221_2017

Revision:
2:87127bdc7e93
Parent:
1:df3b700ba2d9
Child:
3:8134f6d1ca47
diff -r df3b700ba2d9 -r 87127bdc7e93 main.cpp
--- a/main.cpp	Tue Oct 20 08:20:13 2015 +0000
+++ b/main.cpp	Wed Oct 12 07:07:02 2016 +0000
@@ -6,11 +6,8 @@
 //------------------------------------
 
 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()
 {
@@ -40,10 +37,9 @@
                     do {
                         if(state_menu == 0) {
                             pc.printf("LED Test\n");
-                            pc.printf("a.LED Pattern1\n");
-                            pc.printf("d.LED Pattern2\n");
-                        
-                            pc.printf("s.Exit\n");
+                            pc.printf("a.LED ON\n");
+                            pc.printf("s.LED OFF\n");
+                            pc.printf("x.Exit\n");
                             state_menu = 1;
                         }
                         if(pc.readable()) {
@@ -54,40 +50,22 @@
                             switch(data) {
 
                                 case 'a':
-                                    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);
-                                              
-                                         }
-        
-                                            }
+                                    myled = 1;                                    
                                     break;
 
                                 case 's':
+                                    myled =0;
+                                   
+                                    break;
+
+                                case 'x':
                                     state_exit =1;
                                    
                                     break;
 
                                 default:
-                                    pc.printf("please select a or s\n");
-                                    pc.printf("\n");
+                                    pc.printf("plz select a or s\n");
+                                    pc.printf("\n\n");
                                     break;
 
                             }
@@ -109,32 +87,40 @@
                             pc.printf("x.Exit\n");
                             state_menu = 1;
                         }
-                        if(sw.read()) {
+                        if(pc.readable()) {
                             data = pc.getc();
                             pc.printf("\n");
                             state_menu=0;
-                            myled = 1;
-                            pc.putc(1);
-                            }
-                            
-                            else 
-                            {   myled = 0;
-                                pc.putc(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;
 
                                 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;
 
@@ -143,7 +129,10 @@
 
                     break;
 
-                
+                default:
+                    pc.printf("plz select 1 or 2 only\n");
+                    pc.printf("\n\n");
+                    break;
             }
         }