Code used for the 2013 LRM Senior Design Team at VCU 2013 Senior Design Linear Rotary Motor

Dependencies:   mbed

Revision:
2:675f8691f469
Parent:
1:27dcf7ff5b96
Child:
3:0a1b8c86a31e
--- a/main.cpp	Wed Apr 24 00:46:06 2013 +0000
+++ b/main.cpp	Wed Apr 24 18:23:13 2013 +0000
@@ -40,6 +40,7 @@
 float rotary_threshold[rot_pos] = {0};
 float threash = 0;
 int rot_position = 0;
+bool state = 0;                             //Zero is when laser is blocked...1 is when laser is hitting the photocell   
 
 //Labeling the Local file system//
 LocalFileSystem local("local");               // Create the local filesystem under the name "local"
@@ -104,6 +105,7 @@
 void go_to_angle(int angle);
 void rot_pos_inc();
 void rot_pos_dec();
+bool check_state(bool current_state);
 ///////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////MAIN/////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
@@ -1895,7 +1897,7 @@
         rot_position = 0;
         return;
     }//End of if//
-    else if(zero.read() < threash){
+    else if(state != check_state(state)){
         rot_position = rot_position + rot_step;
     }//End of else if//    
 }//End of fucntion
@@ -1908,7 +1910,38 @@
         rot_position = 0;
         return;
     }//End of if//
-    else if(zero.read() < threash){
+    else if(state != check_state(state)){
         rot_position = rot_position - rot_step;
     }//End of else if//     
-}//End of function
\ No newline at end of file
+}//End of function
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////check_state()///////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+bool check_state(bool current_state){
+    if(current_state == 0){
+    //Light was blocked//
+        if(rot_indication.read() > threash){
+            //in this case light is applied//
+            state = 1;
+        }
+        else if(rot_indication.read() < threash){
+            //in this case light has been blocked//
+            state = 0;
+            xbee.printf("\r\nCount Error");
+        }
+    }//End of if
+    else if(current_state == 1){
+    //Light was applied//    
+        if(rot_indication.read() > threash){
+            //in this case light is applied//
+            state = 1;
+            xbee.printf("\r\nCount Error");
+        }
+        else if(rot_indication.read() < threash){
+            //in this case light has been blocked//
+            state = 0;
+        }    
+    }//End of else if
+    return(state);
+}//End of function//
\ No newline at end of file