Dependencies:   mbed

Fork of Version1-SD by Lab 1

main.cpp

Committer:
m211482
Date:
2018-09-20
Revision:
1:2207077f3639
Parent:
0:c8d5f36a69d4

File content as of revision 1:2207077f3639:

#include "mbed.h"

DigitalOut led[5]= {p26,p27,p28,p29,p30};
DigitalIn sw1(p20);
DigitalIn sw2(p19);
int SW1,SW2,i,p;

int main()
{
    while(1) {//while to keep loop going//
        SW1=sw1.read();//read in switches//
        SW2=sw2.read();
        if ((SW1==1) && (SW2==1)) {//if switch one and two are on//
            p=2;
            for(i=0; i<5; i++) { //to turn on only led3 on and the rest off//
                if(i==p) {
                    led[i]=1;
                }//end if//
                else {
                    led[i]=0;
                }//end else
            } //end for//
        }//end if//
        else if (SW1==1) { //if only switch one is on//
            if(p<4) { //to prevent any led greater than 5 to be used//
                led[p]=0;
                p++;
                led[p]=1;
                }
                wait(0.5);
        }//end else if//
        else if (SW2==1) {//if only switch two is on//
            if(p>0) { //to ensure no negative numbers are present//
                led[p]=0;
                p--;
                led[p]=1;
                }
                wait(0.5);
        }//end else if//
    }//end while
}//end main