uotgciytc

Dependencies:   mbed

Committer:
m223204
Date:
Mon Oct 21 00:19:21 2019 +0000
Revision:
0:3a8e35f150dc
I commented the code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m223204 0:3a8e35f150dc 1 // MIDN 3/C Cameron Smith, Eric Donevant, Jacob Jancek
m223204 0:3a8e35f150dc 2 // Confetti Popper Code
m223204 0:3a8e35f150dc 3 // CREATED 10/08/2019
m223204 0:3a8e35f150dc 4 // COMPLETED 10/20/2019
m223204 0:3a8e35f150dc 5 #include "mbed.h"
m223204 0:3a8e35f150dc 6 #include "Motor.h"
m223204 0:3a8e35f150dc 7 #include "Servo.h"
m223204 0:3a8e35f150dc 8
m223204 0:3a8e35f150dc 9
m223204 0:3a8e35f150dc 10 DigitalIn switches [5] = {p15, p16, p17, p18, p19}; //Initializes pins to switches
m223204 0:3a8e35f150dc 11 DigitalOut lights [5] = {p10, p11, p12, p13, p14}; //Initializes pins to LED lights
m223204 0:3a8e35f150dc 12 Servo gun (p24); //Initializes Servo 1 to pin 24
m223204 0:3a8e35f150dc 13 Servo spin (p23); //Initializes Servo 2 to pin 23
m223204 0:3a8e35f150dc 14 Motor jeff (p26, p29, p30); //Initializes DC motor to pins
m223204 0:3a8e35f150dc 15 int h [5]; //Initializes array "h"
m223204 0:3a8e35f150dc 16 float i; //floats variable "i" for servos
m223204 0:3a8e35f150dc 17
m223204 0:3a8e35f150dc 18 int main ()
m223204 0:3a8e35f150dc 19 {
m223204 0:3a8e35f150dc 20 i=0.5; //Float i is equal to 90°
m223204 0:3a8e35f150dc 21 while (1) {
m223204 0:3a8e35f150dc 22 h [0] = switches [0]; //Renames switches to variable "h" for simplification
m223204 0:3a8e35f150dc 23 h [1] = switches [1];
m223204 0:3a8e35f150dc 24 h [2] = switches [2];
m223204 0:3a8e35f150dc 25 h [3] = switches [3];
m223204 0:3a8e35f150dc 26 h [4] = switches [4];
m223204 0:3a8e35f150dc 27
m223204 0:3a8e35f150dc 28 // switch 1 on and 2 off the DC motor will spin forward
m223204 0:3a8e35f150dc 29 //************************************
m223204 0:3a8e35f150dc 30
m223204 0:3a8e35f150dc 31 if ((h [0] == 1) && (h [1] ==0)) { //If switch 1 is on and switch 2 is off
m223204 0:3a8e35f150dc 32 jeff.speed (0.5); //DC motor will spin forward at .5 PWM speed
m223204 0:3a8e35f150dc 33 lights[0] = 1; //LED 1 will light up
m223204 0:3a8e35f150dc 34 }
m223204 0:3a8e35f150dc 35 // switch 1 off and 2 on the DC motor will spin backwards
m223204 0:3a8e35f150dc 36 //************************************
m223204 0:3a8e35f150dc 37
m223204 0:3a8e35f150dc 38 if ((h [0] == 0) && (h [1] == 1)) { //If switch one is off and switch 2 is on
m223204 0:3a8e35f150dc 39 jeff.speed (-0.5); //DC motor will spin backwards at .5 PWM speed
m223204 0:3a8e35f150dc 40 lights[1] = 1; // LEd 2 will light up
m223204 0:3a8e35f150dc 41 }
m223204 0:3a8e35f150dc 42 // switch 1 off and 2 off the DC motor will not spin
m223204 0:3a8e35f150dc 43 //************************************
m223204 0:3a8e35f150dc 44
m223204 0:3a8e35f150dc 45 if (((h [0] == 0) && (h [1] == 0)) || ((h [0] == 1) && (h [1] == 1)) ) {
m223204 0:3a8e35f150dc 46 //If switch 1 and 2 are on or switch 1 and 2 are off
m223204 0:3a8e35f150dc 47 jeff.speed (0); //DC motor will not spin
m223204 0:3a8e35f150dc 48 lights[2] = 1; //LED 3 will light up
m223204 0:3a8e35f150dc 49 }
m223204 0:3a8e35f150dc 50 // switch 3 on and 4 off then servo one turret will spin clockwise
m223204 0:3a8e35f150dc 51 //************************************
m223204 0:3a8e35f150dc 52
m223204 0:3a8e35f150dc 53 if ((h [2] == 1) && (h [3] ==0)) { //If switch 3 is on and switch 4 is off
m223204 0:3a8e35f150dc 54 if (i>1.0) { //If "i" is greater than 180°
m223204 0:3a8e35f150dc 55 i=1.0; //Set "i" to 180°
m223204 0:3a8e35f150dc 56 }
m223204 0:3a8e35f150dc 57 spin = i; //Spin is equal to float "i"
m223204 0:3a8e35f150dc 58 wait (0.1); //Wait .1 seconds
m223204 0:3a8e35f150dc 59 i = i + 0.02; //"i" turns clockwise 3.6°
m223204 0:3a8e35f150dc 60 lights[3] = 1; //LED 4 will light up
m223204 0:3a8e35f150dc 61
m223204 0:3a8e35f150dc 62 }
m223204 0:3a8e35f150dc 63 // switch 3 off and 4 on then turret will spin counter-clockwise
m223204 0:3a8e35f150dc 64 //************************************
m223204 0:3a8e35f150dc 65
m223204 0:3a8e35f150dc 66 if ((h [2] == 0) && (h [3] ==1)) { //If switch 3 is off and switch 4 is on
m223204 0:3a8e35f150dc 67 if (i<0.0) { //If "i" is less than 0°
m223204 0:3a8e35f150dc 68 i=0.0; //Set "i" to 0°
m223204 0:3a8e35f150dc 69 }
m223204 0:3a8e35f150dc 70 spin = i; //Spin is equal to float "i"
m223204 0:3a8e35f150dc 71 wait (0.1); //Wait .1 seconds
m223204 0:3a8e35f150dc 72 i = i - 0.02; //"i" turns counter-clockwise 3.6°
m223204 0:3a8e35f150dc 73 lights[4] = 1; //LED 5 will light up
m223204 0:3a8e35f150dc 74 }
m223204 0:3a8e35f150dc 75 // switch 3 off and 4 off or switch 3 on and 4 on turret will not spin
m223204 0:3a8e35f150dc 76 //***********************************
m223204 0:3a8e35f150dc 77
m223204 0:3a8e35f150dc 78 if (((h [2] == 0) && (h [3] ==0))|| ((h [2] == 1) && (h [3] ==1)))
m223204 0:3a8e35f150dc 79 //If switch 3 and switch 4 are off or switch 3 and switch 4 are on
m223204 0:3a8e35f150dc 80 {
m223204 0:3a8e35f150dc 81 spin = i ; //spin is equal to float "i"
m223204 0:3a8e35f150dc 82 }
m223204 0:3a8e35f150dc 83 // switch 5 on trigger mechanism will go from 180° to 0°
m223204 0:3a8e35f150dc 84 //***********************************
m223204 0:3a8e35f150dc 85 if (h [4] == 1) { //If switch 5 is on
m223204 0:3a8e35f150dc 86 gun = 1.0; //"gun" is at 180°
m223204 0:3a8e35f150dc 87 wait (1.0); //Wait 1 second
m223204 0:3a8e35f150dc 88 gun = 0.0; //"gun" is at 0°
m223204 0:3a8e35f150dc 89 wait (1.0); //Wait 1 second
m223204 0:3a8e35f150dc 90 }
m223204 0:3a8e35f150dc 91
m223204 0:3a8e35f150dc 92
m223204 0:3a8e35f150dc 93
m223204 0:3a8e35f150dc 94 }
m223204 0:3a8e35f150dc 95 }