=3=

Dependencies:   mbed

Fork of Nucleo_serial_menu by FRA221_2015

Files at this revision

API Documentation at this revision

Comitter:
57340500039
Date:
Mon Nov 16 13:23:06 2015 +0000
Parent:
0:f4e546303b4e
Commit message:
meow

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Oct 18 10:09:46 2015 +0000
+++ b/main.cpp	Mon Nov 16 13:23:06 2015 +0000
@@ -1,145 +1,81 @@
 #include "mbed.h"
-
-//------------------------------------
-// Hyperterminal configuration
-// 9600 bauds, 8-bit data, no parity
-//------------------------------------
-
-Serial pc(SERIAL_TX, SERIAL_RX);
-
-DigitalOut myled(LED1);
-
-int main()
-{
-
-    uint8_t state_menu=0;
-    uint8_t state_show=0;
-    uint8_t state_exit =0;
-    uint8_t data;
-
-    myled = 0;
-    pc.printf("Hello World !\n");
-    while(1) {
-        if(state_show == 0) {
-            pc.printf("Menu\n");
-            pc.printf("1.LED Test\n");
-            pc.printf("2.Print Test\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 ON\n");
-                            pc.printf("s.LED OFF\n");
-                            pc.printf("x.Exit\n");
-                            state_menu = 1;
-                        }
-                        if(pc.readable()) {
-                            data = pc.getc();
-                            pc.printf("\n");
-                            state_menu=0;
-
-                            switch(data) {
-
-                                case 'a':
-                                    myled = 1;                                    
-                                    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");
-                                    break;
-
-                            }
-                        }
+#include <string.h>
 
-
-
-                    } while(state_exit ==0);
-                    pc.printf("\n\n");
-                    break;
-
-                case '2':
-
-                    do {
-                        if(state_menu == 0) {
-                            pc.printf("LED Test\n");
-                            pc.printf("a.Menu 2 TEST\n");
-                            pc.printf("s.Run\n");
-                            pc.printf("x.Exit\n");
-                            state_menu = 1;
-                        }
-                        if(pc.readable()) {
-                            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;
-
-                                default:
-                                    pc.printf("plz select a or s\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;
-            }
+DigitalOut led1(D11);
+DigitalOut led2(D3);
+DigitalOut led3(D4);
+DigitalOut led4(D5);
+DigitalOut led5(D6);
+DigitalOut led6(D7);
+DigitalOut led7(D9);
+DigitalOut led8(D10);
+DigitalOut led[8] = {led1,led2,led3,led4,led5,led6,led7,led8};
+AnalogIn analog_value(A0);
+ 
+//------------------------------------
+ 
+//------------------------------------
+ 
+Serial pc(D8, D2); //D8 = Tx, D2 = Rx 
+int funcA(){
+    uint8_t a=0;
+    uint8_t b=0;
+    char input[2]={0,0};
+    
+        input[0] = pc.getc();
+        input[1] = pc.getc();
+        a = input[0]-'0';
+        b = input[1]-'0';
+        if(a>=9||a<0) a = 0;
+        if(b>=9||b<0) b = 0;
+        
+        switch(a){
+            case 0: led5 = 0; led6 = 0; led7 = 0; led8 = 0; break;
+            case 1: led5 = 1; led6 = 0; led7 = 0; led8 = 0; break;
+            case 2: led5 = 0; led6 = 1; led7 = 0; led8 = 0; break;
+            case 3: led5 = 1; led6 = 1; led7 = 0; led8 = 0; break;
+            case 4: led5 = 0; led6 = 0; led7 = 1; led8 = 0; break;
+            case 5: led5 = 1; led6 = 0; led7 = 1; led8 = 0; break;
+            case 6: led5 = 0; led6 = 1; led7 = 1; led8 = 0; break;
+            case 7: led5 = 1; led6 = 1; led7 = 1; led8 = 0; break;
+            case 8: led5 = 0; led6 = 0; led7 = 0; led8 = 1; break;
+            case 9: led5 = 1; led6 = 0; led7 = 0; led8 = 1; break;
         }
-
-
-
-
-
-
+        switch(b){
+            case 0: led1 = 0; led2 = 0; led3 = 0; led4 = 0; break;
+            case 1: led1 = 1; led2 = 0; led3 = 0; led4 = 0; break;
+            case 2: led1 = 0; led2 = 1; led3 = 0; led4 = 0; break;
+            case 3: led1 = 1; led2 = 1; led3 = 0; led4 = 0; break;
+            case 4: led1 = 0; led2 = 0; led3 = 1; led4 = 0; break;
+            case 5: led1 = 1; led2 = 0; led3 = 1; led4 = 0; break;
+            case 6: led1 = 0; led2 = 1; led3 = 1; led4 = 0; break;
+            case 7: led1 = 1; led2 = 1; led3 = 1; led4 = 0; break;
+            case 8: led1 = 0; led2 = 0; led3 = 0; led4 = 1; break;
+            case 9: led1 = 1; led2 = 0; led3 = 0; led4 = 1; break;
+        }
+    return 0;
+}
+int funcB(){
+    float meas;
+    meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+    meas = meas * 3.3; // Change the value to be in the 0 to 33 range
+    pc.printf("%f\n",meas); 
+    return 0;
+}
+int main(){
+    char input = 'x';
+    
+    while(1){
+        pc.printf("mode a : input 2 digits number.\r\n");
+        pc.printf("mode b : read analog from VR.\r\n\r\n");
+        pc.printf("input : ");
+        input = pc.getc();
+        switch(input){
+            case 'a': pc.printf("mode a:\r\n");funcA();break;
+            case 'b': pc.printf("mode b:\r\n");funcB();break;
+        }
+        
+        pc.printf("\r\n**************************\r\n\r\n");
     }
-}
+ 
+}
\ No newline at end of file