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
main.cpp@0:d18a5e3c79c9, 2018-10-23 (annotated)
- Committer:
- dantg
- Date:
- Tue Oct 23 10:55:13 2018 +0000
- Revision:
- 0:d18a5e3c79c9
Useless Box Code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dantg | 0:d18a5e3c79c9 | 1 | #include "mbed.h" |
| dantg | 0:d18a5e3c79c9 | 2 | |
| dantg | 0:d18a5e3c79c9 | 3 | PwmOut Backward_Motor_Control (p22); |
| dantg | 0:d18a5e3c79c9 | 4 | PwmOut Forward_Motor_Control (p21); |
| dantg | 0:d18a5e3c79c9 | 5 | DigitalIn Backward_Switch (p17); |
| dantg | 0:d18a5e3c79c9 | 6 | DigitalIn Forward_Switch (p18); |
| dantg | 0:d18a5e3c79c9 | 7 | DigitalIn Limit_Switch (p19); |
| dantg | 0:d18a5e3c79c9 | 8 | |
| dantg | 0:d18a5e3c79c9 | 9 | int main() { |
| dantg | 0:d18a5e3c79c9 | 10 | |
| dantg | 0:d18a5e3c79c9 | 11 | Backward_Motor_Control.period (0.02); //Sets the backward motor speed to 50hz |
| dantg | 0:d18a5e3c79c9 | 12 | Forward_Motor_Control.period (0.02); //Sets the forward motor speed to 50hz |
| dantg | 0:d18a5e3c79c9 | 13 | |
| dantg | 0:d18a5e3c79c9 | 14 | while(1) { |
| dantg | 0:d18a5e3c79c9 | 15 | if (Forward_Switch.read() == 1) { //When a person presses the switch |
| dantg | 0:d18a5e3c79c9 | 16 | Forward_Motor_Control = 0.5; //Motor moves forward at a steady speed |
| dantg | 0:d18a5e3c79c9 | 17 | Backward_Motor_Control = 0; |
| dantg | 0:d18a5e3c79c9 | 18 | wait (0.1); //Pause to allow time for the PWM signal |
| dantg | 0:d18a5e3c79c9 | 19 | } |
| dantg | 0:d18a5e3c79c9 | 20 | else if (Backward_Switch.read() == 1 && Limit_Switch.read() == 0) { //When the arm presses the switch |
| dantg | 0:d18a5e3c79c9 | 21 | Forward_Motor_Control = 0; //Motor moves backwards at a steady speed |
| dantg | 0:d18a5e3c79c9 | 22 | Backward_Motor_Control = 0.5; |
| dantg | 0:d18a5e3c79c9 | 23 | wait (0.1); //Pause to allow time for the PWM signal |
| dantg | 0:d18a5e3c79c9 | 24 | } |
| dantg | 0:d18a5e3c79c9 | 25 | else if (Backward_Switch.read() == 1 && Limit_Switch.read() == 1) { //When the arm presses the limit switch |
| dantg | 0:d18a5e3c79c9 | 26 | Forward_Motor_Control = 0; //Motor stops moving |
| dantg | 0:d18a5e3c79c9 | 27 | Backward_Motor_Control = 0; |
| dantg | 0:d18a5e3c79c9 | 28 | wait (0.1); //Pause to allow time for the PWM signal |
| dantg | 0:d18a5e3c79c9 | 29 | } |
| dantg | 0:d18a5e3c79c9 | 30 | } |
| dantg | 0:d18a5e3c79c9 | 31 | } |
| dantg | 0:d18a5e3c79c9 | 32 | |
| dantg | 0:d18a5e3c79c9 | 33 | |
| dantg | 0:d18a5e3c79c9 | 34 |