4180 LabTeam - Spring '18
/
PWMdimming
Lab1-Part2
Fork of HelloWorld by
Diff: main.cpp
- Revision:
- 2:9dfa56288155
- Parent:
- 0:fb6bbc10ffa0
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); + } }