Tom Murchison / Mbed 2 deprecated UselessBox

Dependencies:   mbed

Revision:
0:89d76ea57469
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 30 04:30:44 2016 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+
+DigitalIn switchin(p19);                                                        //Set pin 19 as input for when switch is towards the arm
+DigitalIn switchout(p18);                                                       //Set pin 18 as input for when switch is away from arm
+DigitalIn limit(p30);                                                           //Set pin 30 as input for limit switch
+
+DigitalOut armout(p21);                                                         //Set pin 21 as output for when motor is turning CCW towards switch
+DigitalOut armin(p22);                                                          //Set pin 22 as output for when motor is turning CW into box
+
+int main()
+{
+    while(1)                                                                    //Repeat indefinitely
+    {
+        armin = 0;                                                              //Ensure all motor function is stopped
+            
+            if ((switchin) && (switchout==0))                                   //If the switch is pushed towards the arm
+                                             {
+                                               while(switchout)
+                                                               {
+                                                                armout = 1;     //The MOSFET enabling the motor to turn CCW (towards the switch) is activated
+                                                                wait(0.002);    //PWM is used to run motor at a slower speed with full torque so it can still push the switch
+                                                                armout = 0;
+                                                                wait(0.008);
+                                                                }
+                                             }
+            else if ((switchin==0) && (switchout))                              //If the switch is not pushed towards the arm
+                                                    {
+                                                     while(limit)               //And the limit switch is not actuated (it is normally closed)
+                                                                                //Once the limit switch is actuated the program will end and the motor will stop
+                                                                 {
+                                                                  armout = 0;   //The MOSFET enabling the motor to turn CCW is deactivated
+                                                                  armin = 1;    //The MOSFET enabling the motor to turn CW (back into box) is activated
+                                                                  wait(0.002);  //PWM is again used to protect the limit switch
+                                                                  armin = 0;
+                                                                  wait(0.008);
+                                                                  }
+                                                    }
+    }
+}