Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- tmurchison
- Date:
- 2016-11-30
- Revision:
- 0:89d76ea57469
File content as of revision 0:89d76ea57469:
#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); } } } }