Austin Hague / Mbed 2 deprecated Lab2_C

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Lab 1 Program B
00002 // Program Allow the user to do different functions with the LED lights using the Logic Switches 1 and 2.
00003 // Written by: MIDN 3/C Hague 9/28/15
00004 
00005 #include "mbed.h"
00006 
00007 DigitalIn LS1(p16);// Switch 1
00008 DigitalIn LS2(p17);// Switch 2
00009 
00010 
00011 
00012 
00013 
00014 int main()
00015 {
00016 
00017     int number1, number2;// used for rand functions later
00018 
00019     while(1) { //Continuous While Loop
00020 
00021         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
00022 
00023             BusOut lights(p26, p27, p28, p29, p30); // Date bus for LEDs
00024 
00025             if (LS1 == 0 && LS2 == 0) {// If both switches are off LEDs Flash
00026 
00027                 lights = 31; //All LEDs On
00028                 wait(.2); // Wait .2 seconds
00029                 lights = 0; //All LEDs off
00030                 wait(.8); // Wait .8 seconds
00031 
00032             }
00033 
00034             if (LS1 == 1 && LS2 == 0) {// If Switch 1 is on and Switch 2 is off Lgiht up LEDs left to Right then back down
00035 
00036                 lights = 16; // LED 1 on
00037                 wait(.4); // Wait .4 seconds
00038                 lights = 24; // LED 1&2 on
00039                 wait(.4); // Wait .4 seconds
00040                 lights = 28; // LED 1&2&3 on
00041                 wait(.4); // Wait .4 seconds
00042                 lights = 30; // LED 1&2&3&4 on
00043                 wait(.4); //Wait .4 seconds
00044                 lights = 31; // LED 1&2&3&4&5 on
00045                 wait(.4); //Wait .4 seconds
00046                 lights = 30; //LED 1&2&3&4 on
00047                 wait(.4); //Wait .4 seconds
00048                 lights = 28; // LED 1&2&3 on
00049                 wait(.4); //Wait .4 seconds
00050                 lights = 24; //LED 1&2 on
00051                 wait(.4); //Wait .4 seconds
00052                 lights = 16; //LED 1 on
00053 
00054             }
00055 
00056             if (LS1 == 0 && LS2 == 1) {
00057 
00058                 lights = 16; // LED 1 on
00059                 wait(.125); // Wait .4 seconds
00060                 lights = 8; // LED 1&2 on
00061                 wait(.125); // Wait .4 seconds
00062                 lights = 4; // LED 1&2&3 on
00063                 wait(.125); // Wait .4 seconds
00064                 lights = 2; // LED 1&2&3&4 on
00065                 wait(.125); //Wait .4 seconds
00066                 lights = 1; // LED 1&2&3&4&5 on
00067                 wait(.125); //Wait .4 seconds
00068                 lights = 2; //LED 1&2&3&4 on
00069                 wait(.125); //Wait .4 seconds
00070                 lights = 4; // LED 1&2&3 on
00071                 wait(.125); //Wait .4 seconds
00072                 lights = 8; //LED 1&2 on
00073                 wait(.125); //Wait .4 seconds
00074                 lights = 16; //LED 1 on
00075 
00076             }
00077         }
00078         
00079         number1 = rand()%5;// Used for two random LEDs
00080         number2 = rand()%5;// Used for two random LEDs
00081 
00082         if (LS1 == 1 && LS2 == 1) {// second if statement different use of communicating to LEDs
00083             
00084             DigitalOut D_lights[5]={p26, p27, p28, p29, p30}; //DigitalOut to use pins with array
00085             
00086             if((number1 != number2) ) { // If both of the numbers do not equal eachother therefore there is always two leds lit
00087                 
00088                 D_lights[number1]=1;
00089                 D_lights[number2]=1;
00090                 wait(1);
00091             }
00092 
00093         }
00094 
00095     }
00096 }