Dependencies:   mbed

main.cpp

Committer:
m182376
Date:
2015-09-28
Revision:
0:fc1503207544
Child:
1:4c233736f4b2

File content as of revision 0:fc1503207544:

#include "mbed.h"

DigitalIn LS1(p16);// Switch 1
DigitalIn LS2(p17);// Switch 2





int main()
{

    int number1, number2;

    while(1) { //Continuous While Loop

        if ((LS1 == 0 && LS2 == 0) || (LS1 == 1 && LS2 == 0) || (LS1 == 0 && LS2 == 1)) {

            BusOut lights(p26, p27, p28, p29, p30); // Date bus for LEDs

            if (LS1 == 0 && LS2 == 0) {// If both switches are off LEDs Flash

                lights = 31; //All LEDs On
                wait(.2); // Wait .2 seconds
                lights = 0; //All LEDs off
                wait(.8); // Wait .8 seconds

            }

            if (LS1 == 1 && LS2 == 0) {// If Switch 1 is on and Switch 2 is off Lgiht up LEDs left to Right then back down

                lights = 16; // LED 1 on
                wait(.4); // Wait .4 seconds
                lights = 24; // LED 1&2 on
                wait(.4); // Wait .4 seconds
                lights = 28; // LED 1&2&3 on
                wait(.4); // Wait .4 seconds
                lights = 30; // LED 1&2&3&4 on
                wait(.4); //Wait .4 seconds
                lights = 31; // LED 1&2&3&4&5 on
                wait(.4); //Wait .4 seconds
                lights = 30; //LED 1&2&3&4 on
                wait(.4); //Wait .4 seconds
                lights = 28; // LED 1&2&3 on
                wait(.4); //Wait .4 seconds
                lights = 24; //LED 1&2 on
                wait(.4); //Wait .4 seconds
                lights = 16; //LED 1 on

            }

            if (LS1 == 0 && LS2 == 1) {

                lights = 16; // LED 1 on
                wait(.125); // Wait .4 seconds
                lights = 8; // LED 1&2 on
                wait(.125); // Wait .4 seconds
                lights = 4; // LED 1&2&3 on
                wait(.125); // Wait .4 seconds
                lights = 2; // LED 1&2&3&4 on
                wait(.125); //Wait .4 seconds
                lights = 1; // LED 1&2&3&4&5 on
                wait(.125); //Wait .4 seconds
                lights = 2; //LED 1&2&3&4 on
                wait(.125); //Wait .4 seconds
                lights = 4; // LED 1&2&3 on
                wait(.125); //Wait .4 seconds
                lights = 8; //LED 1&2 on
                wait(.125); //Wait .4 seconds
                lights = 16; //LED 1 on

            }
        }
        
        number1 = rand()%5;
        number2 = rand()%5;

        if (LS1 == 1 && LS2 == 1) {
            
            DigitalOut D_lights[5]={p26, p27, p28, p29, p30};
            
            if((number1 != number2) ) {
                
                D_lights[number1]=1;
                D_lights[number2]=1;
                wait(1);
            }

        }

    }
}