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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:d18a5e3c79c9
diff -r 000000000000 -r d18a5e3c79c9 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Oct 23 10:55:13 2018 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+
+PwmOut Backward_Motor_Control (p22);
+PwmOut Forward_Motor_Control (p21);
+DigitalIn Backward_Switch (p17);
+DigitalIn Forward_Switch (p18);
+DigitalIn Limit_Switch (p19);
+
+int main() {
+
+ Backward_Motor_Control.period (0.02); //Sets the backward motor speed to 50hz
+ Forward_Motor_Control.period (0.02); //Sets the forward motor speed to 50hz
+
+ while(1) {
+ if (Forward_Switch.read() == 1) { //When a person presses the switch
+ Forward_Motor_Control = 0.5; //Motor moves forward at a steady speed
+ Backward_Motor_Control = 0;
+ wait (0.1); //Pause to allow time for the PWM signal
+ }
+ else if (Backward_Switch.read() == 1 && Limit_Switch.read() == 0) { //When the arm presses the switch
+ Forward_Motor_Control = 0; //Motor moves backwards at a steady speed
+ Backward_Motor_Control = 0.5;
+ wait (0.1); //Pause to allow time for the PWM signal
+ }
+ else if (Backward_Switch.read() == 1 && Limit_Switch.read() == 1) { //When the arm presses the limit switch
+ Forward_Motor_Control = 0; //Motor stops moving
+ Backward_Motor_Control = 0;
+ wait (0.1); //Pause to allow time for the PWM signal
+ }
+ }
+}
+
+
+
\ No newline at end of file