0508_Lab3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
KongpobMaksap
Date:
Sun Oct 25 11:37:36 2015 +0000
Commit message:
555

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 8d4673851e31 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 25 11:37:36 2015 +0000
@@ -0,0 +1,117 @@
+//57340500005
+//57340500008
+// Lab 3
+// 25/10/2015
+#include "mbed.h"
+
+DigitalOut l1(D2),l2(D3),l3(D4),l4(D5),l5(D6),l6(D7),l7(D8),l8(D9);
+DigitalIn sw(D13);
+Serial pc(USBTX, USBRX);
+void mode1();
+void mode2();
+int main() 
+{
+    char x;
+    uint8_t menu=1;
+    pc.printf("\nHello World!\n");
+    while(1)
+    {
+        if(menu)
+        {
+            //print menu
+            pc.printf("MENU\nSelect mode\n1 : LED show time\n2 : Input from switch\n > ");
+            menu=0;
+        }
+        if(pc.readable())
+        {
+            x=pc.getc();
+            pc.printf("%c\n",x);
+            switch(x)
+            {
+                case '1':
+                    mode1();
+                    menu=1;
+                    break;
+                case '2':
+                    mode2();
+                    menu=1;
+                    break;
+                default:
+                    pc.printf("\nPlease Input 1 or 2 > ");
+            }
+        }
+    }
+}
+
+void mode1()
+{
+    char x;
+    uint8_t ch=0;
+    pc.printf("Input A or D (S to exit mode 1) > ");
+    do
+    {
+        if(pc.readable()||ch)
+        {
+            if(!ch)
+                x=pc.getc();
+            pc.printf("%c\n",x);
+            if(x!='a'&&x!='A'&&x!='d'&&x!='D'&&x!='s'&&x!='S')
+                pc.printf("Please Input A or D or S only\n > ");
+            else
+            {
+                switch(x)
+                {
+                    case 'A':
+                    case 'a':
+                        //show led1
+                        ch=0;
+                        do
+                        {
+                            l1=1; l3=1; l5=1; l7=1; wait_ms(300);
+                            l1=0; l3=0; l5=0; l7=0; 
+                            l2=1; l4=1; l6=1; l8=1; wait_ms(300);
+                            l2=0; l4=0; l6=0; l8=0;
+                            if(pc.readable())
+                            {
+                                ch=1;
+                                x=pc.getc();
+                            }
+                        }while(!ch);
+                        break;
+                    case 'D':
+                    case 'd':
+                        //show led2
+                        ch=0;
+                        do
+                        {
+                            l1=1; l8=1; wait_ms(100);
+                            l2=1; l7=1; wait_ms(100);
+                            l3=1; l6=1; wait_ms(100);
+                            l4=1; l5=1; wait_ms(100);
+        
+                            l4=0; l5=0; wait_ms(100);
+                            l3=0; l6=0; wait_ms(100);
+                            l2=0; l7=0; wait_ms(100);
+                            l1=0; l8=0; wait_ms(100);
+                            if(pc.readable())
+                            {
+                                ch=1;
+                                x=pc.getc();
+                            }
+                        }while(!ch);
+                        break;
+                    default:
+                }
+            }
+        }
+    }
+    while(x!='s'&&x!='S');
+}
+
+void mode2()
+{
+    if(sw.read()==1)
+        pc.printf("\nSwitch >>>>> 1\n");
+    else
+        pc.printf("\nSwitch >>>>> 0\n");
+}
\ No newline at end of file
diff -r 000000000000 -r 8d4673851e31 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 25 11:37:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file