Team Ascent / Mbed 2 deprecated TDPCode1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Dbee16
Date:
Thu Mar 26 10:33:37 2015 +0000
Parent:
10:2970279fce70
Commit message:
This is the Remote Control Bluetooth; I changed it to using switch case statements. It should work(haven't tested).

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 13 10:20:18 2015 +0000
+++ b/main.cpp	Thu Mar 26 10:33:37 2015 +0000
@@ -74,7 +74,8 @@
     }
 }
 
-void manual_mode(){
+void manual_mode()
+{
     int direction = 0x11;
     unsigned char rem_dir; //remote_direction
 
@@ -91,33 +92,35 @@
         //}
 
         blue.printf("Thanks, calculating it now, you entered %c\n",rem_dir);
-        if(   ( rem_dir == 'f')   ) {
-            direction = 0x11;
-            blue.printf("You wanted to go straight\n");
-        }
-        if (   (rem_dir == 'b' )     ) {
+        switch (rem_dir) {
 
-            direction = 0x00;
-            blue.printf("You wanted to go backwards\n");
-        }
-        if (   (rem_dir == 'l' )   ) {
+            case('f'):
+                direction = 0x11;
+                blue.printf("You wanted to go straight\n");
+                break;
+                case( 'b' )    :
+                    direction = 0x00;
+                blue.printf("You wanted to go backwards\n");
+                break;
+            case( 'l' )  :
 
-            direction = 0x01;
-            blue.printf("You wanted to spin anti-clockwise\n");
+                direction = 0x01;
+                blue.printf("You wanted to spin anti-clockwise\n");
 
-        }
-        if (   (rem_dir == 'r' )   )  {
+                break;
+            case ('r') :
 
-            direction = 0x10;
-            blue.printf("You wanted to spin clockwise\n");
+                direction = 0x10;
+                blue.printf("You wanted to spin clockwise\n");
+                break;
+            case ('s') :
+                motor_r.write(0);
+                motor_l.write(0);
+                blue.printf("STAAAAHP\n");
+                break;
         }
-         if (rem_dir =='s') {
 
-            motor_r.write(0);
-            motor_l.write(0);
-            blue.printf("STAAAAHP\n");
-        }else{
-            wait(0.1);
+        wait(0.1);
         blue.printf("What duty left?\n");
         while ( blue.readable()==0 ) {}               // loops until there is an input from the user
         char l_speed = blue.getc();
@@ -129,12 +132,10 @@
         int l_result = l_speed - '0';
         int r_result = r_speed - '0';
         set_direction(direction, (float)l_result/10, (float)r_result/10);
-       }
-        
+    }
 
-    }
-    
-    }
+
+}
 int main()
 {
 //Set PWM frequency to 1000Hz
@@ -145,9 +146,9 @@
     motor_rb=0;
     motor_lf=0;
     motor_lb=0;
-    while(1){
+    while(1) {
         manual_mode();
-        }
+    }
 
     /* //Also Working Demo
     wait(2);