Dependencies: mbed
Fork of Version1-SD by
main.cpp@1:2207077f3639, 2018-09-20 (annotated)
- Committer:
- m211482
- Date:
- Thu Sep 20 15:35:55 2018 +0000
- Revision:
- 1:2207077f3639
- Parent:
- 0:c8d5f36a69d4
b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m211482 | 0:c8d5f36a69d4 | 1 | #include "mbed.h" |
m211482 | 0:c8d5f36a69d4 | 2 | |
m211482 | 0:c8d5f36a69d4 | 3 | DigitalOut led[5]= {p26,p27,p28,p29,p30}; |
m211482 | 0:c8d5f36a69d4 | 4 | DigitalIn sw1(p20); |
m211482 | 0:c8d5f36a69d4 | 5 | DigitalIn sw2(p19); |
m211482 | 0:c8d5f36a69d4 | 6 | int SW1,SW2,i,p; |
m211482 | 0:c8d5f36a69d4 | 7 | |
m211482 | 0:c8d5f36a69d4 | 8 | int main() |
m211482 | 0:c8d5f36a69d4 | 9 | { |
m211482 | 0:c8d5f36a69d4 | 10 | while(1) {//while to keep loop going// |
m211482 | 1:2207077f3639 | 11 | SW1=sw1.read();//read in switches// |
m211482 | 0:c8d5f36a69d4 | 12 | SW2=sw2.read(); |
m211482 | 0:c8d5f36a69d4 | 13 | if ((SW1==1) && (SW2==1)) {//if switch one and two are on// |
m211482 | 1:2207077f3639 | 14 | p=2; |
m211482 | 1:2207077f3639 | 15 | for(i=0; i<5; i++) { //to turn on only led3 on and the rest off// |
m211482 | 1:2207077f3639 | 16 | if(i==p) { |
m211482 | 1:2207077f3639 | 17 | led[i]=1; |
m211482 | 0:c8d5f36a69d4 | 18 | }//end if// |
m211482 | 1:2207077f3639 | 19 | else { |
m211482 | 1:2207077f3639 | 20 | led[i]=0; |
m211482 | 1:2207077f3639 | 21 | }//end else |
m211482 | 1:2207077f3639 | 22 | } //end for// |
m211482 | 0:c8d5f36a69d4 | 23 | }//end if// |
m211482 | 0:c8d5f36a69d4 | 24 | else if (SW1==1) { //if only switch one is on// |
m211482 | 1:2207077f3639 | 25 | if(p<4) { //to prevent any led greater than 5 to be used// |
m211482 | 0:c8d5f36a69d4 | 26 | led[p]=0; |
m211482 | 0:c8d5f36a69d4 | 27 | p++; |
m211482 | 0:c8d5f36a69d4 | 28 | led[p]=1; |
m211482 | 1:2207077f3639 | 29 | } |
m211482 | 0:c8d5f36a69d4 | 30 | wait(0.5); |
m211482 | 0:c8d5f36a69d4 | 31 | }//end else if// |
m211482 | 0:c8d5f36a69d4 | 32 | else if (SW2==1) {//if only switch two is on// |
m211482 | 1:2207077f3639 | 33 | if(p>0) { //to ensure no negative numbers are present// |
m211482 | 1:2207077f3639 | 34 | led[p]=0; |
m211482 | 1:2207077f3639 | 35 | p--; |
m211482 | 1:2207077f3639 | 36 | led[p]=1; |
m211482 | 1:2207077f3639 | 37 | } |
m211482 | 0:c8d5f36a69d4 | 38 | wait(0.5); |
m211482 | 0:c8d5f36a69d4 | 39 | }//end else if// |
m211482 | 0:c8d5f36a69d4 | 40 | }//end while |
m211482 | 0:c8d5f36a69d4 | 41 | }//end main |
m211482 | 0:c8d5f36a69d4 | 42 | |
m211482 | 0:c8d5f36a69d4 | 43 | |
m211482 | 0:c8d5f36a69d4 | 44 | |
m211482 | 0:c8d5f36a69d4 | 45 | |
m211482 | 0:c8d5f36a69d4 | 46 | |
m211482 | 0:c8d5f36a69d4 | 47 | |
m211482 | 0:c8d5f36a69d4 | 48 | |
m211482 | 0:c8d5f36a69d4 | 49 | |
m211482 | 0:c8d5f36a69d4 | 50 | |
m211482 | 0:c8d5f36a69d4 | 51 |