uotgciytc

Dependencies:   mbed

main.cpp

Committer:
m223204
Date:
2019-10-21
Revision:
0:3a8e35f150dc

File content as of revision 0:3a8e35f150dc:

// MIDN 3/C Cameron Smith, Eric Donevant, Jacob Jancek
// Confetti Popper Code
// CREATED 10/08/2019
// COMPLETED 10/20/2019
#include "mbed.h"
#include "Motor.h"
#include "Servo.h"


DigitalIn switches [5] = {p15, p16, p17, p18, p19}; //Initializes pins to switches
DigitalOut lights [5] = {p10, p11, p12, p13, p14};  //Initializes pins to LED lights
Servo gun (p24);                                    //Initializes Servo 1 to pin 24
Servo spin (p23);                                   //Initializes Servo 2 to pin 23
Motor jeff (p26, p29, p30);                         //Initializes DC motor to pins
int h [5];                                          //Initializes array "h"
float i;                                            //floats variable "i" for servos

int main ()
{
    i=0.5;                                      //Float i is equal to 90°
    while (1) {
        h [0] = switches [0];                   //Renames switches to variable "h" for simplification
        h [1] = switches [1];
        h [2] = switches [2];
        h [3] = switches [3];
        h [4] = switches [4];

        // switch 1 on and 2 off the DC motor will spin forward
        //************************************

        if ((h [0] == 1) && (h [1] ==0)) {        //If switch 1 is on and switch 2 is off
            jeff.speed (0.5);                     //DC motor will spin forward at .5 PWM speed
            lights[0] = 1;                        //LED 1 will light up
        }
        // switch 1 off and 2 on the DC motor will spin backwards
        //************************************

        if ((h [0] == 0) && (h [1] == 1)) {      //If switch one is off and switch 2 is on
            jeff.speed (-0.5);                   //DC motor will spin backwards at .5 PWM speed
            lights[1] = 1;                       // LEd 2 will light up
        }
        // switch 1 off and 2 off the DC motor will not spin
        //************************************

        if (((h [0] == 0) && (h [1] == 0)) || ((h [0] == 1) && (h [1] == 1)) ) {
            //If switch 1 and 2 are on or switch 1 and 2 are off
            jeff.speed (0);                     //DC motor will not spin
            lights[2] = 1;                      //LED 3 will light up
        }
        // switch 3 on and 4 off then servo one turret will spin clockwise
        //************************************

        if ((h [2] == 1) && (h [3] ==0)) {  //If switch 3 is on and switch 4 is off
            if (i>1.0) {                    //If "i" is greater than 180°
                i=1.0;                      //Set "i" to 180°
            }
            spin = i;                       //Spin is equal to float "i"
            wait (0.1);                     //Wait .1 seconds
            i = i + 0.02;                   //"i" turns clockwise 3.6°
            lights[3] = 1;                  //LED 4 will light up

        }
        // switch 3 off and 4 on then turret will spin counter-clockwise
        //************************************

        if ((h [2] == 0) && (h [3] ==1)) { //If switch 3 is off and switch 4 is on
            if (i<0.0) {                   //If "i" is less than 0°
                i=0.0;                     //Set "i" to 0°
            }
            spin = i;                      //Spin is equal to float "i"
            wait (0.1);                    //Wait .1 seconds
            i = i - 0.02;                  //"i" turns counter-clockwise 3.6°
            lights[4] = 1;                 //LED 5 will light up
        }
        // switch 3 off and 4 off or switch 3 on and 4 on turret will not spin
        //***********************************

        if (((h [2] == 0) && (h [3] ==0))|| ((h [2] == 1) && (h [3] ==1)))
        //If switch 3 and switch 4 are off or switch 3 and switch 4 are on
        {
            spin = i ;                   //spin is equal to float "i"
        }
        // switch 5 on trigger mechanism will go from 180° to 0°
        //***********************************
        if (h [4] == 1) {                //If switch 5 is on
            gun = 1.0;                   //"gun" is at 180°
            wait (1.0);                  //Wait 1 second
            gun = 0.0;                   //"gun" is at 0°
            wait (1.0);                  //Wait 1 second
        }



    }
}