Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of speed_control by
Diff: main.cpp
- Revision:
- 0:dc1151db1e78
- Child:
- 1:68ca288dd6b5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 23 08:07:01 2015 +0000 @@ -0,0 +1,24 @@ +#include "mbed.h" + +PwmOut motor_pwm(D5); +DigitalOut dir(D4); + +const int pwm_frequency = 10000; // PWM frequency +bool direction = false; // Motor direction +float duty_cycle = 0; +int main() +{ + dir.write(direction); // Write motor direction + motor_pwm.period(1/pwm_frequency); // Motor PWM period + motor_pwm.write(duty_cycle); // Set motor speed + + while(true) { + for(int i = 0; i<10; i++) { + duty_cycle = 0.1*i; + motor_pwm.write(duty_cycle); + wait(0.2); + } + duty_cycle = 0; + motor_pwm.write(duty_cycle); + } +} \ No newline at end of file