![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Use the PortIn Class to make a switch to control the lights
Dependencies: mbed
Fork of PortIn_HelloWorld by
Revision 2:b23912b62b2e, committed 2014-10-17
- Comitter:
- shiyilei
- Date:
- Fri Oct 17 01:43:17 2014 +0000
- Parent:
- 1:618efc742844
- Commit message:
- use the PortIn class to make a switch
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 618efc742844 -r b23912b62b2e main.cpp --- a/main.cpp Sun Sep 21 17:24:49 2014 +0000 +++ b/main.cpp Fri Oct 17 01:43:17 2014 +0000 @@ -1,17 +1,25 @@ -// Switch on an LED if any of mbed pins 21-26 is high - +/**************************************** +*File: a switch +*Creator:Jacob Shi +*Time :2014/10/16 +*Description: use the PortIn class to make a +*switch to control the lights +*******************************************/ #include "mbed.h" - -PortIn p(Port2, 0x0000003F); // p21-p26 -DigitalOut ind(LED4); - -int main() { - while(1) { - int pins = p.read(); - if(pins) { - ind = 1; - } else { - ind = 0; +PortIn keys(Port0,0x00000003); +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +int main() +{ + while(1) + { + switch(keys) + { + case 1:myled1=1;myled2=0;break; + case 2:myled1=0;myled2=1;break; + case 3:myled1==1;myled2=1;break; + default:break; } } + } \ No newline at end of file