Wheelchair control

Dependencies:   BNO055 mbed

Fork of wheelchaircontrol by ryan lin

Revision:
6:8cd00c26bb47
Parent:
5:e0ccaab3959a
diff -r e0ccaab3959a -r 8cd00c26bb47 main.cpp
--- a/main.cpp	Tue Jul 17 07:19:04 2018 +0000
+++ b/main.cpp	Tue Jul 17 19:19:26 2018 +0000
@@ -1,79 +1,92 @@
 #include "wheelchair.h"
 
+// Initialize Pins
 AnalogIn x(A0);
 AnalogIn y(A1);
-
+ 
 DigitalOut off(D0);
 DigitalOut on(D1);
 DigitalOut up(D2);
 DigitalOut down(D3);
-
+ 
 Wheelchair smart(xDir,yDir);
 
 int main(void)
 {
     on = 1;
     while(1){
- /*   if( pc.readable()) {
-        char c = pc.getc();
-        if( c == 'w') {
-            pc.printf("up \n");
-            smart.forward(); 
+    /*  
+        // Waiting for command
+        if (pc.readable()) {
+            char c = pc.getc();
+            
+            // Move Forward
+            if (c == 'w') {
+                pc.printf("up \n");
+                smart.forward(); 
             }
         
-        else if( c == 'd') {
-            pc.printf("left \n");
-            smart.left();
+            // Move Left
+            else if (c == 'd') {
+                pc.printf("left \n");
+                smart.left();
+            }
+        
+            // Move Right
+            else if (c == 'a') {
+                pc.printf("right \n");
+                smart.right();
             }
         
-        else if( c == 'a') {
-            pc.printf("right \n");
-            smart.right();
-            }
-        
-        else if( c == 's') {
-            pc.printf("down \n");
-            smart.backward();
+            // Move Backward
+            else if (c == 's') {
+                pc.printf("down \n");
+                smart.backward();
             }
-        
-        else {
-            pc.printf("none \n");
-            smart.stop();
-            if( c == 'o') {
-               pc.printf("turning on");
-               on = 0;
-               wait(process);
-               on = 1; 
+            
+            // Read non-move commands
+            else {
+                pc.printf("none \n");
+                smart.stop();
+                
+                // Turn On
+                if (c == 'o') {
+                   pc.printf("Turning on.\n");
+                   on = 0;
+                   wait(process);
+                   on = 1; 
+                }
+                
+                // Turn Off
+                else if (c == 'k') {
+                    off = 0;
+                    wait(process);
+                    off = 1;
+                }
+                
+                
+                else if (c == 'u') {
+                    up = 0;
+                    wait(process);
+                    up = 1;
                 }
             
-            else if( c == 'k') {
-                off = 0;
-                wait(process);
-                off = 1;
+                else if (c == 'p') {
+                    down = 0;
+                    wait(process);
+                    down = 1;
                 }
-        
-            else if( c == 'u') {
-                up = 0;
-                wait(process);
-                up = 1;
-                }
+            }   
+        }
         
-            else if( c == 'p') {
-                down = 0;
-                wait(process);
-                down = 1;
-                }
-            }
-           }
-           
-    else {
-       pc.printf("Nothing pressed \n");
-       smart.stop();
-            }
-   */
-    smart.move(x,y); 
-    wait(process);
-       }
-
+        else {
+            pc.printf("Nothing pressed.\n");
+            smart.stop();
+        }
+        */
+        
+        smart.move(x,y); 
+        wait(process);
+    }
 }