
Final Revision
main.cpp@1:4c233736f4b2, 2015-09-29 (annotated)
- Committer:
- m182376
- Date:
- Tue Sep 29 13:49:02 2015 +0000
- Revision:
- 1:4c233736f4b2
- Parent:
- 0:fc1503207544
Final Revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m182376 | 1:4c233736f4b2 | 1 | // Lab 1 Program B |
m182376 | 1:4c233736f4b2 | 2 | // Program Allow the user to do different functions with the LED lights using the Logic Switches 1 and 2. |
m182376 | 1:4c233736f4b2 | 3 | // Written by: MIDN 3/C Hague 9/28/15 |
m182376 | 1:4c233736f4b2 | 4 | |
m182376 | 0:fc1503207544 | 5 | #include "mbed.h" |
m182376 | 0:fc1503207544 | 6 | |
m182376 | 0:fc1503207544 | 7 | DigitalIn LS1(p16);// Switch 1 |
m182376 | 0:fc1503207544 | 8 | DigitalIn LS2(p17);// Switch 2 |
m182376 | 0:fc1503207544 | 9 | |
m182376 | 0:fc1503207544 | 10 | |
m182376 | 0:fc1503207544 | 11 | |
m182376 | 0:fc1503207544 | 12 | |
m182376 | 0:fc1503207544 | 13 | |
m182376 | 0:fc1503207544 | 14 | int main() |
m182376 | 0:fc1503207544 | 15 | { |
m182376 | 0:fc1503207544 | 16 | |
m182376 | 1:4c233736f4b2 | 17 | int number1, number2;// used for rand functions later |
m182376 | 0:fc1503207544 | 18 | |
m182376 | 0:fc1503207544 | 19 | while(1) { //Continuous While Loop |
m182376 | 0:fc1503207544 | 20 | |
m182376 | 1:4c233736f4b2 | 21 | if ((LS1 == 0 && LS2 == 0) || (LS1 == 1 && LS2 == 0) || (LS1 == 0 && LS2 == 1)) {// Huge if statement so that I can use BusOut and DigitalOut in the next if |
m182376 | 0:fc1503207544 | 22 | |
m182376 | 0:fc1503207544 | 23 | BusOut lights(p26, p27, p28, p29, p30); // Date bus for LEDs |
m182376 | 0:fc1503207544 | 24 | |
m182376 | 0:fc1503207544 | 25 | if (LS1 == 0 && LS2 == 0) {// If both switches are off LEDs Flash |
m182376 | 0:fc1503207544 | 26 | |
m182376 | 0:fc1503207544 | 27 | lights = 31; //All LEDs On |
m182376 | 0:fc1503207544 | 28 | wait(.2); // Wait .2 seconds |
m182376 | 0:fc1503207544 | 29 | lights = 0; //All LEDs off |
m182376 | 0:fc1503207544 | 30 | wait(.8); // Wait .8 seconds |
m182376 | 0:fc1503207544 | 31 | |
m182376 | 0:fc1503207544 | 32 | } |
m182376 | 0:fc1503207544 | 33 | |
m182376 | 0:fc1503207544 | 34 | if (LS1 == 1 && LS2 == 0) {// If Switch 1 is on and Switch 2 is off Lgiht up LEDs left to Right then back down |
m182376 | 0:fc1503207544 | 35 | |
m182376 | 0:fc1503207544 | 36 | lights = 16; // LED 1 on |
m182376 | 0:fc1503207544 | 37 | wait(.4); // Wait .4 seconds |
m182376 | 0:fc1503207544 | 38 | lights = 24; // LED 1&2 on |
m182376 | 0:fc1503207544 | 39 | wait(.4); // Wait .4 seconds |
m182376 | 0:fc1503207544 | 40 | lights = 28; // LED 1&2&3 on |
m182376 | 0:fc1503207544 | 41 | wait(.4); // Wait .4 seconds |
m182376 | 0:fc1503207544 | 42 | lights = 30; // LED 1&2&3&4 on |
m182376 | 0:fc1503207544 | 43 | wait(.4); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 44 | lights = 31; // LED 1&2&3&4&5 on |
m182376 | 0:fc1503207544 | 45 | wait(.4); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 46 | lights = 30; //LED 1&2&3&4 on |
m182376 | 0:fc1503207544 | 47 | wait(.4); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 48 | lights = 28; // LED 1&2&3 on |
m182376 | 0:fc1503207544 | 49 | wait(.4); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 50 | lights = 24; //LED 1&2 on |
m182376 | 0:fc1503207544 | 51 | wait(.4); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 52 | lights = 16; //LED 1 on |
m182376 | 0:fc1503207544 | 53 | |
m182376 | 0:fc1503207544 | 54 | } |
m182376 | 0:fc1503207544 | 55 | |
m182376 | 0:fc1503207544 | 56 | if (LS1 == 0 && LS2 == 1) { |
m182376 | 0:fc1503207544 | 57 | |
m182376 | 0:fc1503207544 | 58 | lights = 16; // LED 1 on |
m182376 | 0:fc1503207544 | 59 | wait(.125); // Wait .4 seconds |
m182376 | 0:fc1503207544 | 60 | lights = 8; // LED 1&2 on |
m182376 | 0:fc1503207544 | 61 | wait(.125); // Wait .4 seconds |
m182376 | 0:fc1503207544 | 62 | lights = 4; // LED 1&2&3 on |
m182376 | 0:fc1503207544 | 63 | wait(.125); // Wait .4 seconds |
m182376 | 0:fc1503207544 | 64 | lights = 2; // LED 1&2&3&4 on |
m182376 | 0:fc1503207544 | 65 | wait(.125); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 66 | lights = 1; // LED 1&2&3&4&5 on |
m182376 | 0:fc1503207544 | 67 | wait(.125); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 68 | lights = 2; //LED 1&2&3&4 on |
m182376 | 0:fc1503207544 | 69 | wait(.125); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 70 | lights = 4; // LED 1&2&3 on |
m182376 | 0:fc1503207544 | 71 | wait(.125); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 72 | lights = 8; //LED 1&2 on |
m182376 | 0:fc1503207544 | 73 | wait(.125); //Wait .4 seconds |
m182376 | 0:fc1503207544 | 74 | lights = 16; //LED 1 on |
m182376 | 0:fc1503207544 | 75 | |
m182376 | 0:fc1503207544 | 76 | } |
m182376 | 0:fc1503207544 | 77 | } |
m182376 | 0:fc1503207544 | 78 | |
m182376 | 1:4c233736f4b2 | 79 | number1 = rand()%5;// Used for two random LEDs |
m182376 | 1:4c233736f4b2 | 80 | number2 = rand()%5;// Used for two random LEDs |
m182376 | 0:fc1503207544 | 81 | |
m182376 | 1:4c233736f4b2 | 82 | if (LS1 == 1 && LS2 == 1) {// second if statement different use of communicating to LEDs |
m182376 | 0:fc1503207544 | 83 | |
m182376 | 1:4c233736f4b2 | 84 | DigitalOut D_lights[5]={p26, p27, p28, p29, p30}; //DigitalOut to use pins with array |
m182376 | 0:fc1503207544 | 85 | |
m182376 | 1:4c233736f4b2 | 86 | if((number1 != number2) ) { // If both of the numbers do not equal eachother therefore there is always two leds lit |
m182376 | 0:fc1503207544 | 87 | |
m182376 | 0:fc1503207544 | 88 | D_lights[number1]=1; |
m182376 | 0:fc1503207544 | 89 | D_lights[number2]=1; |
m182376 | 0:fc1503207544 | 90 | wait(1); |
m182376 | 0:fc1503207544 | 91 | } |
m182376 | 0:fc1503207544 | 92 | |
m182376 | 0:fc1503207544 | 93 | } |
m182376 | 0:fc1503207544 | 94 | |
m182376 | 0:fc1503207544 | 95 | } |
m182376 | 0:fc1503207544 | 96 | } |