updated test

Dependencies:   TextLCD mbed

Fork of CE713-V01 by malcolm lear

Files at this revision

API Documentation at this revision

Comitter:
Faiyaz
Date:
Thu Nov 09 10:09:30 2017 +0000
Parent:
0:4bc9e88c2cff
Commit message:
test version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 4bc9e88c2cff -r 76c4a55fbac4 main.cpp
--- a/main.cpp	Mon Oct 30 11:27:45 2017 +0000
+++ b/main.cpp	Thu Nov 09 10:09:30 2017 +0000
@@ -231,35 +231,90 @@
     float spos = 0;                                   // Test servo position
     InitLEDs();
     InitMotion();
-    InitServos();
+    InitServos(); 
+    
+    float temp = -99;
+    int dist = -99;
+    char Key = 'X';
   
     while(1) {
+        
+        
         int a,b;
+        /*
         for (b = 0; b < 4; b++ ) {                    // select all 4 led states
             for (a = 1; a < 9; a++ ) {                // set all 8 leds to selected state
                 SetLED (a,b);                         // set led 'a' to state 'b'
                 wait(.05);                            // wait 0.05 second
             }
         }
+        */
+        
+        int firstOnSwitch = 0;
+        
         for (a= 1; a < 9; a++ ) {                     // map Switch states to led's
             SetLED (a,(ReadSwitch(a) + 1));           //
-            wait(.05);                                // wait 0.05 second
+            
+            if(ReadSwitch(a) == 1)
+            {
+                firstOnSwitch = a; 
+            }
+            
+            wait(0.05);                               // wait 0.05 second
         }
+        
+        switch(firstOnSwitch)
+        {
+            case 1:
+                temp = ReadTemp();                      // get temperature
+                lcd.cls();                                    // clear lcd
+                lcd.printf("Temp = %f\n", temp);              // print temperature
+                wait(1);                                      // wait 1 second
+                break;
+
+            case 2:
+                dist = ReadSonar();                       // get distance
+                lcd.cls();
+                lcd.printf("Distance = %d\n", dist);          // print result
+                //lcd.printf("Servo = %f\n", spos);             // print servo pos
+                wait(0.5);
+                break;
+
+            case 3:
+                Key = FindKeyChar();                     // look for Key pressed
+                lcd.cls();
+                lcd.printf("Key = %c\n", Key);                // print result
+                wait(0.5);                                      // wait 1 second
+                break;
+
+            // operator is doesn't match any case constant (+, -, *, /)
+            default:
+                lcd.cls();
+            }
+
+        
+        /*
         float temp = ReadTemp();                      // get temperature
         lcd.cls();                                    // clear lcd
         lcd.printf("Temp = %f\n", temp);              // print temperature
         wait(1);                                      // wait 1 second
         lcd.cls();                                    // clear lcd
+        
+        
         int swch = ReadSwitches();                    // look at Switch states   
         lcd.printf("Switches = %d\n", swch);          // print result
+        
+        
         char Key = FindKeyChar();                     // look for Key pressed
         lcd.printf("Key = %c\n", Key);                // print result
         wait(1);                                      // wait 1 second
         lcd.cls();                                    // clear lcd
+        
         int dist = ReadSonar();                       // get distance
         lcd.printf("Distance = %d\n", dist);          // print result
         lcd.printf("Servo = %f\n", spos);             // print servo pos
         wait(1);                                      // wait 1 second
+        
         ReadMotion();                                 // read new data in from the MPU-6050
         lcd.cls();                                    // clear lcd
         lcd.locate(0,0);                              // print at start of first line
@@ -267,6 +322,7 @@
         lcd.locate(0,1);                              // print at start of second line
         lcd.printf("x%.1f y%.1f z%.1f", GyroRate[0], GyroRate[1], GyroRate[2]);               
         wait(.4);                                     // wait 0.4 second
+        
         if (spos < 1) {                               // is servo at upper limit of 1
           spos += .1;                                 // increment servo position
         }                                             //
@@ -274,5 +330,6 @@
           spos = -1;                                  // reset servo position
         }                                             //
         Servo1(spos);                                 // update servo
+        */   
     }
 }