lab1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
csggreen
Date:
Fri Nov 24 04:07:26 2017 +0000
Commit message:
lab1

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 28a06ea42f7e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Nov 24 04:07:26 2017 +0000
@@ -0,0 +1,190 @@
+#include "mbed.h"
+
+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(USER_BUTTON);
+int switchled;
+
+void readswitch(){
+    if(sw_in1==1&&sw_in2==1) switchled=1 ;
+    else if(sw_in1==0&&sw_in2==0) switchled=2;
+    else if(sw_in3==0&&sw_in2==0&&sw_in1==1)switchled=3;
+    else switchled=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() {
+    while(1) {
+        readswitch();
+        ledout();
+    }
+    }
diff -r 000000000000 -r 28a06ea42f7e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Nov 24 04:07:26 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27
\ No newline at end of file