Keegan Hu
/
Ex_limit
limit switch example
Diff: main.cpp
- Revision:
- 0:bd903e56077a
- Child:
- 1:fe798c459fdb
diff -r 000000000000 -r bd903e56077a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jul 17 00:15:18 2018 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" + +PwmOut mypwm(PA_10); +InterruptIn button(PB_3); +DigitalOut myled(LED1); +void stop(); + +int main() { + button.rise(&stop); + mypwm.period_ms(10); + mypwm.pulsewidth_ms(9); + + while(1) { + myled = !myled; + wait(1); + } +} + +void stop() +{ wait(0.01); + if(button.read() == 1) + { + mypwm.write(0); + } +} +