Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@0:c8d5f36a69d4, 2018-09-20 (annotated)
- Committer:
- m211482
- Date:
- Thu Sep 20 15:22:12 2018 +0000
- Revision:
- 0:c8d5f36a69d4
Version1-SD
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 | 0:c8d5f36a69d4 | 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 | 0:c8d5f36a69d4 | 14 | p=2; |
m211482 | 0:c8d5f36a69d4 | 15 | for(i=0;i<5;i++){//to turn on only led3 on and the rest off// |
m211482 | 0:c8d5f36a69d4 | 16 | if(i==p){ |
m211482 | 0:c8d5f36a69d4 | 17 | led[i]=1; |
m211482 | 0:c8d5f36a69d4 | 18 | }//end if// |
m211482 | 0:c8d5f36a69d4 | 19 | else{ |
m211482 | 0:c8d5f36a69d4 | 20 | led[i]=0; |
m211482 | 0:c8d5f36a69d4 | 21 | }//end else |
m211482 | 0:c8d5f36a69d4 | 22 | } //end for// |
m211482 | 0:c8d5f36a69d4 | 23 | }//end if// |
m211482 | 0:c8d5f36a69d4 | 24 | else if (SW1==1) { //if only switch one is on// |
m211482 | 0:c8d5f36a69d4 | 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 | 0:c8d5f36a69d4 | 29 | wait(0.5); |
m211482 | 0:c8d5f36a69d4 | 30 | }//end if// |
m211482 | 0:c8d5f36a69d4 | 31 | }//end else if// |
m211482 | 0:c8d5f36a69d4 | 32 | else if (SW2==1) {//if only switch two is on// |
m211482 | 0:c8d5f36a69d4 | 33 | if(p>0){//to ensure no negative numbers are present// |
m211482 | 0:c8d5f36a69d4 | 34 | led[p]=0; |
m211482 | 0:c8d5f36a69d4 | 35 | p--; |
m211482 | 0:c8d5f36a69d4 | 36 | led[p]=1; |
m211482 | 0:c8d5f36a69d4 | 37 | wait(0.5); |
m211482 | 0:c8d5f36a69d4 | 38 | }//end if// |
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 |