lab3

Dependencies:   mbed

Revision:
0:5f038207add9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 23 14:50:37 2017 +0000
@@ -0,0 +1,151 @@
+#include "mbed.h"
+
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+Serial pc(D1, D0);
+DigitalIn enable(A0);
+DigitalIn enable1(A1);
+DigitalIn enable2(A2);
+BusOut led(D2, D3, D4, D5);
+int main()
+{
+
+    uint8_t state_menu=0;
+    uint8_t state_show=0;
+    uint8_t state_exit =0;
+    uint8_t data;
+
+    pc.printf("\n\n");
+    while(1) {
+        if(state_show == 0) {
+            pc.printf("************\n");
+            pc.printf("   Menu   \n");
+            pc.printf("************\n");
+            pc.printf("1.LED Pattern\n");
+            pc.printf("2.Read Logic\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 Pattern1\n");
+                                pc.printf("s.LED Pattern2\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':
+                                AA:
+                                pc.printf("Pattern 1 \n");
+                                while(1){                                    
+                                   if (pc.readable()){
+                                       data = pc.getc();
+                                       if (data == 's')
+                                    {
+                                        goto SS;
+                                    }
+                                       if (data == 'x')
+                                    {
+                                           goto XX;
+                                           }
+                                       }
+                                   else{
+                                        led =1;
+                                        wait(0.2);
+                                        led =2;
+                                        wait(0.2);
+                                        led =4;
+                                        wait(0.2);
+                                        led =8;
+                                        wait(0.2);
+                                       }
+                                   }
+                                    break;
+                                case's':
+                                SS:
+                                pc.printf("Pattern 2 \n");
+                                    while(1){                                    
+                                   if (pc.readable()){
+                                       data = pc.getc();
+                                       if (data == 'a')
+                                       {
+                                            goto AA;
+                                       }
+                                       if (data == 'x')
+                                       {
+                                            goto XX;
+                                            }
+                                       }
+                                   else{
+                                       led =8;
+                                       wait(0.2);
+                                       led =4;
+                                       wait(0.2);
+                                       led =2;
+                                       wait(0.2);
+                                       led =1;
+                                       wait(0.2);
+                                       }
+                                   }
+
+                                case 'x':
+                                XX:
+                                    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");
+                    break;
+
+                case '2':
+
+                    do {
+                        if(state_menu == 0) {
+                            while(state_exit ==0){
+                                pc.printf("Logic input : ");
+                                pc.printf("%d",enable.read());
+                                pc.printf("%d",enable1.read());
+                                pc.printf("%d",enable2.read());
+                                pc.printf("\n");
+                                state_exit =1;
+                                }
+                            
+                        }
+                        
+                    } while(state_exit ==0);
+                    pc.printf("\n");
+                    break;
+
+
+                default:
+                    pc.printf("plz select 1 or 2 only\n");
+                    pc.printf("\n");
+                    break;
+            }
+        }
+    }
+}
\ No newline at end of file