0720_Lab3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
chinetion
Date:
Tue Oct 20 12:12:08 2015 +0000
Commit message:
Finish

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 3d6fe97bd8ca main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 20 12:12:08 2015 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+
+Serial se(SERIAL_TX,SERIAL_RX);
+DigitalOut led[] = {D2,D3,D4,D5,D6,D7,D8,D9};
+DigitalIn sw(D15);
+uint8_t  mode = 0;
+uint8_t input_data = '0';
+char  input(){  if(se.readable()) input_data = se.getc(); return input_data;}
+int main() {
+    while(1){
+        if(input()=='0'){
+           se.printf("-------Menu-------\n1.Leds\n2.Read Switch\n"); 
+           while(1){if(input()!='0')break;}
+        }
+        else if(input()=='1'){
+            se.printf("-------Leds-------\na.Pattern 1\nd.Pattern 2\ns.Exit\n");
+            while(1){
+             if(input()=='a'||input()=='A'){
+                for(int x=0;x<=7;x++){
+                    led[x]=1;
+                    wait(0.1);
+                    led[x]=0;
+                    if(input()=='s'||input()=='S'||input()=='d'||input()=='D')break;
+                    else input_data='a';
+                }
+             }
+             else if(input()=='d'||input()=='D'){
+                 for(int x=7;x>=0;x--){
+                    led[x]=1;
+                    wait(0.1);
+                    led[x]=0;
+                    if(input()=='s'||input()=='S'||input()=='a'||input()=='A')break;
+                    else input_data='d';
+                }
+             }
+             else if(input()=='s'||input()=='S'){input_data='0';break;}     
+            }
+        }
+        else if(input()=='2'){
+            se.printf("------Switch------\n");
+            se.printf("Switch : %d\n",sw.read());
+            input_data='0';
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 3d6fe97bd8ca mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 20 12:12:08 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file