Lab 1 Program A

Dependencies:   mbed

main.cpp

Committer:
mattsims12
Date:
2015-09-29
Revision:
0:0db95f8cd85f

File content as of revision 0:0db95f8cd85f:

/*Lab 1 Program A
  Makes led's shift based on which input switches are on.
  Matthew Sims
  Section 1001
*/

#include "mbed.h"

DigitalOut out[]= {p30,p29,p28,p27,p26}; //sets 5 output pins connected to circut board led's
DigitalIn in[]={p16,p17};                //sets 2 inputs to the pins the switches are connected to

int main()
{
    out[2]=1;                           //Initial postion led 2 lit
    int lit=2;                          //Records which led is lit

    /*Infinite loop that checks which inputts are on every cycle and changes led's bassed on inputs*/

    while(1) {
        if(in[0]==1 && in[1]==1) {                   //Checks first instance
            out[lit]=0;                 //Turns off currently on led
            lit=2;                      //Picks middle led to be lit 
            out[lit]=1;                 //Turns on the selected led
            wait(.5);                   //Turns on the selected led
        } else if(in[0]==1 && in[1]==0) {            //Checks second instance
            if(lit<4) {                 //Makes sure it stops at end of array
                out[lit]=0;             //Turns previously on led off
                lit++;                  //Picks led to right
                out[lit]=1;             //Turns on led
                wait(.5);               //Waits to start loop again
            }
        } else if(in[1]==1 && in[0]==0) {            //Same as last loop, but moves led's to left instead of right.
            if(lit>0) {
                out[lit]=0;
                lit--;
                out[lit]=1;
                wait(.5);
            }
        }
    }
}