lab3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
csggreen
Date:
Fri Nov 24 04:09:20 2017 +0000
Commit message:
lab3

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
diff -r 000000000000 -r c0fd379f0df0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 24 04:09:20 2017 +0000
@@ -0,0 +1,280 @@
+#include "mbed.h"
+
+
+Serial pc(D1, D0);
+
+DigitalOut gsled0(D2);
+DigitalOut gsled1(D3);
+DigitalOut gsled2(D4);
+DigitalOut gsled3(D5);
+DigitalOut gsled4(D6);
+DigitalOut gsled5(D7);
+DigitalOut gsled6(D8);
+DigitalOut gsled7(D9);
+DigitalIn sw_in1(D10);
+DigitalIn sw_in2(D11);
+DigitalIn sw_in3(D12);
+int switchled;
+int x =0;
+
+void ledout(){
+   if(switchled==1){
+             gsled0 = 1;
+             wait(0.1);
+             gsled1 = 1;
+             wait(0.1);
+             gsled2 = 1;
+             wait(0.1);
+             gsled3 = 1;
+             wait(0.1);
+             gsled4 = 1;
+             wait(0.1);
+             gsled5 = 1;
+             wait(0.1);
+             gsled6 = 1;
+             wait(0.1);
+             gsled7 = 1;
+             wait(0.1);
+             gsled7 = 0;
+             wait(0.1);
+             gsled6 = 0;
+             wait(0.1);
+             gsled5 = 0;
+             wait(0.1);
+             gsled4 = 0;
+             wait(0.1);
+             gsled3 = 0;
+             wait(0.1);
+             gsled2 = 0;
+             wait(0.1);
+             gsled1 = 0;
+             wait(0.1);
+             gsled0 = 0;
+             wait(0.1);
+             }
+       
+    else if(switchled==2){
+             gsled0 = 1;
+             gsled7 = 1;
+             wait(0.1);
+             gsled0 = 0;
+             gsled7 = 0;
+             gsled1 = 1;
+             gsled6 = 1;
+             wait(0.1);
+             gsled1 = 0;
+             gsled6 = 0;
+             gsled2 = 1;
+             gsled5 = 1;
+             wait(0.1);
+             gsled2 = 0;
+             gsled5 = 0;
+             gsled3 = 1;
+             gsled4 = 1;
+             wait(0.1);
+             gsled3 = 0;
+             gsled4 = 0;
+        }
+        else if(switchled==3){
+             gsled0 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             gsled2 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             gsled2 = 1;
+             gsled3 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             gsled3 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             gsled2 = 1;
+             gsled3 = 1;
+             gsled4 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             gsled3 = 0;
+             gsled4 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             gsled2 = 1;
+             gsled3 = 1;
+             gsled4 = 1;
+             gsled5 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             gsled3 = 0;
+             gsled4 = 0;
+             gsled5 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             gsled2 = 1;
+             gsled3 = 1;
+             gsled4 = 1;
+             gsled5 = 1;
+             gsled6 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             gsled3 = 0;
+             gsled4 = 0;
+             gsled5 = 0;
+             gsled6 = 0;
+             wait(0.3);
+             gsled0 = 1;
+             gsled1 = 1;
+             gsled2 = 1;
+             gsled3 = 1;
+             gsled4 = 1;
+             gsled5 = 1;
+             gsled6 = 1;
+             gsled7 = 1;
+             wait(0.2);
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             gsled3 = 0;
+             gsled4 = 0;
+             gsled5 = 0;
+             gsled6 = 0;
+             gsled7 = 0;
+             wait(0.1);
+
+        }
+        else {
+             gsled0 = 0;
+             gsled1 = 0;
+             gsled2 = 0;
+             gsled3 = 0;
+             gsled4 = 0;
+             gsled5 = 0;
+             gsled6 = 0;
+             gsled7 = 0;
+        }
+   
+}
+
+
+int main()
+{
+
+    uint8_t state_menu=0;
+    uint8_t state_show=0;
+    uint8_t state_exit =0;
+    uint8_t data;
+  
+    while(1) {
+        if(state_show == 0) {
+            pc.printf("************\n");
+            pc.printf("   MENU   \n");
+            pc.printf("************\n");
+            pc.printf("1.PLAY LED \n");
+            pc.printf("2.READ SWITCH\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("PLAY LED\n");
+                                pc.printf("a.Pattern1\n");
+                                pc.printf("d.Pattern2\n");
+                                pc.printf("s.Pattern3 and Exit\n");
+                                state_menu = 1;
+                            }
+                            
+                        if(pc.readable()) {
+                            data = pc.getc();
+                            pc.printf("\n");
+                            state_menu=0;
+
+                            switch(data) {
+
+                                case 'a':
+                                    pc.printf("-->Pattern1<-- \n\n");
+                                    switchled = 1;
+                                    ledout();                         
+                                    break;
+
+                                case 'd':
+                                    pc.printf("-->pattern2<-- \n\n");
+                                    switchled = 2;
+                                    ledout();   
+                                    break;
+
+                                case 's':
+                                    pc.printf("-->pattern3 and exit<-- \n\n");
+                                    switchled = 3;
+                                    ledout();
+                                    state_exit =1;   
+                                    break;
+                                default:
+                                    state_menu=0;
+                                    break;
+                            }
+                        }
+                    } while(state_exit ==0); 
+                    pc.printf("\n");
+                    break;
+
+                case '2':
+
+                    do {
+                        if(state_menu == 0) {
+                            pc.printf("Switch 1 status %d\n",sw_in1.read());
+                            pc.printf("Switch 2 status %d\n",sw_in2.read());
+                            pc.printf("Switch 3 status %d\n",sw_in3.read());
+                            state_menu = 1;
+                            state_exit =1;
+                            state_show =0; 
+                            
+                        }
+                        if(pc.readable()) {
+                            data = pc.getc();
+                            pc.printf("\n");
+                            state_menu=0;
+                        }
+                        default:
+                            state_menu=0;
+                            break;
+            }
+            while(state_exit ==0);
+                    pc.printf("\n");
+                    break;
+
+            }
+        }
+    }
+}
+
diff -r 000000000000 -r c0fd379f0df0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 24 04:09:20 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/fb8e0ae1cceb
\ No newline at end of file