![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
motor test
Fork of speed_control by
main.cpp
- Committer:
- bjornnijhuis
- Date:
- 2015-09-23
- Revision:
- 1:68ca288dd6b5
- Parent:
- 0:dc1151db1e78
File content as of revision 1:68ca288dd6b5:
#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(3); } duty_cycle = 0; motor_pwm.write(duty_cycle); } }