bubble blowing / Mbed 2 deprecated Useless_Box_MkII

Dependencies:   mbed

main.cpp

Committer:
dantg
Date:
2018-10-23
Revision:
0:d18a5e3c79c9

File content as of revision 0:d18a5e3c79c9:

#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
        }
    }
}