Miguel Castañeda
/
Motor1
1
Diff: main.cpp
- Revision:
- 0:78b238cef288
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Apr 06 00:39:19 2017 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" + +DigitalOut my_led(LED1); +InterruptIn my_button(USER_BUTTON); +PwmOut my_pwm(PB_3); + +void pressed() { + if (my_pwm.read() == 0.25) { + my_pwm.write(0.75); + } + else { + my_pwm.write(0.25); + } +} + +int main() +{ + // Set PWM + my_pwm.period_ms(10); + my_pwm.write(0.2); + + // Set button + my_button.fall(&pressed); + + while (1) { + my_led = !my_led; + wait(0.2); // 500 ms + } +}