0720_Lab1

Dependencies:   mbed

Revision:
0:f17d9dc54c1d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 15 19:10:23 2015 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+
+
+DigitalOut led[] = {D2,D3,D4,D5,D6,D7,D8,D9};
+DigitalIn In[] = {D10,D11,D12};
+double speed=0.1;
+int pat = 1,tog=0;
+void check(){
+    tog=0;
+    if(In[0]){pat++;tog=1;}
+    if(In[1])speed+=0.02;
+    if(In[2])speed-=0.02;
+    if(speed<=0.02)speed=0.02;
+    else if(speed>=1)speed=1;
+    if(pat>3)pat=1;
+}
+int main(){
+    
+  while(1){
+  if(pat==1){
+        for(int x=0;x<=7;x++){
+              led[x]=1;
+              wait(speed);
+              led[x]=0;
+                check();if(tog==1)break;
+        }
+    }
+    if(pat==2){
+        for(int x=0;x<=7;x++){
+              led[x]=1;
+              wait(speed);
+              check();if(tog==1)break;
+        }
+        for(int x=0;x<=7;x++){
+              led[x]=0;
+              wait(speed);
+              check();if(tog==1)break;
+        }
+        
+    }
+    if(pat==3){
+        for(int x=0;x<=3;x++){
+              led[x]=1;
+              led[7-x]=1;
+              wait(speed);
+              check();if(tog==1)break;
+        }
+        for(int x=3;x>=0;x--){
+              led[x]=0;
+              led[7-x]=0;
+              wait(speed);
+              check();if(tog==1)break;
+        }
+  }
+  }
+  }