4180 LabTeam - Spring '18
/
PWMdimming
Lab1-Part2
Fork of HelloWorld by
Revision 2:9dfa56288155, committed 2018-01-18
- Comitter:
- bjs9
- Date:
- Thu Jan 18 03:03:05 2018 +0000
- Parent:
- 1:03c191369089
- Commit message:
- Part 2 of Lab1;
Changed in this revision
PinDetect.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 03c191369089 -r 9dfa56288155 PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Thu Jan 18 03:03:05 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 03c191369089 -r 9dfa56288155 main.cpp --- a/main.cpp Sun Jan 01 20:57:57 2012 +0000 +++ b/main.cpp Thu Jan 18 03:03:05 2018 +0000 @@ -1,12 +1,36 @@ #include "mbed.h" +#include "PinDetect.h" + +PwmOut myled(p26); +PinDetect pb1(p16); +PinDetect pb2(p17); + + +float illuminate = 0.1f; -DigitalOut myled(LED1); - +void pb1_dim_callback (void) { + if(illuminate > 0.0f){ + illuminate -= 0.1f; + } + } +void pb2_bright_callback (void) { + if(illuminate < 1.0f){ + illuminate += 0.1f; + } + } int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } + pb1.mode(PullUp); + pb2.mode(PullUp); + wait(.01); + + pb1.attach_deasserted(&pb1_dim_callback); + pb2.attach_deasserted(&pb2_bright_callback); + + pb1.setSampleFrequency(); + pb2.setSampleFrequency(); + + while(1) { + myled= illuminate; + wait(.1); + } }