joseph chen
/
Nucleo_pwm2_12345
wsdfghjk
Revision 1:d15a148acde3, committed 2016-05-31
- Comitter:
- ittraining
- Date:
- Tue May 31 07:44:45 2016 +0000
- Parent:
- 0:b82c05c12d48
- Commit message:
- test1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 20 14:09:54 2014 +0000 +++ b/main.cpp Tue May 31 07:44:45 2016 +0000 @@ -2,28 +2,25 @@ DigitalOut my_led(LED1); InterruptIn my_button(USER_BUTTON); -PwmOut my_pwm(PB_3); - +PwmOut servo(PB_3); +float offset=0; void pressed() { - if (my_pwm.read() == 0.25) { - my_pwm.write(0.75); - } - else { - my_pwm.write(0.25); - } + + servo.pulsewidth_ms(1); + offset=0; } -int main() -{ - // Set PWM - my_pwm.period_ms(10); - my_pwm.write(0.5); + +int main() { - // Set button + // Set button my_button.fall(&pressed); - + servo.period(0.020); // servo requires a 20ms period while (1) { - my_led = !my_led; - wait(0.5); // 500 ms + for(offset=0.0; offset<0.001; offset+=0.0001) { + servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms + wait(0.25); + my_led = !my_led; + } } }
--- a/mbed.bld Thu Feb 20 14:09:54 2014 +0000 +++ b/mbed.bld Tue May 31 07:44:45 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb \ No newline at end of file