![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
motor test
Fork of speed_control by
main.cpp@1:68ca288dd6b5, 2015-09-23 (annotated)
- Committer:
- bjornnijhuis
- Date:
- Wed Sep 23 08:11:54 2015 +0000
- Revision:
- 1:68ca288dd6b5
- Parent:
- 0:dc1151db1e78
Increased wait time
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bjornnijhuis | 0:dc1151db1e78 | 1 | #include "mbed.h" |
bjornnijhuis | 0:dc1151db1e78 | 2 | |
bjornnijhuis | 0:dc1151db1e78 | 3 | PwmOut motor_pwm(D5); |
bjornnijhuis | 0:dc1151db1e78 | 4 | DigitalOut dir(D4); |
bjornnijhuis | 0:dc1151db1e78 | 5 | |
bjornnijhuis | 0:dc1151db1e78 | 6 | const int pwm_frequency = 10000; // PWM frequency |
bjornnijhuis | 0:dc1151db1e78 | 7 | bool direction = false; // Motor direction |
bjornnijhuis | 0:dc1151db1e78 | 8 | float duty_cycle = 0; |
bjornnijhuis | 0:dc1151db1e78 | 9 | int main() |
bjornnijhuis | 0:dc1151db1e78 | 10 | { |
bjornnijhuis | 0:dc1151db1e78 | 11 | dir.write(direction); // Write motor direction |
bjornnijhuis | 0:dc1151db1e78 | 12 | motor_pwm.period(1/pwm_frequency); // Motor PWM period |
bjornnijhuis | 0:dc1151db1e78 | 13 | motor_pwm.write(duty_cycle); // Set motor speed |
bjornnijhuis | 0:dc1151db1e78 | 14 | |
bjornnijhuis | 0:dc1151db1e78 | 15 | while(true) { |
bjornnijhuis | 0:dc1151db1e78 | 16 | for(int i = 0; i<10; i++) { |
bjornnijhuis | 0:dc1151db1e78 | 17 | duty_cycle = 0.1*i; |
bjornnijhuis | 0:dc1151db1e78 | 18 | motor_pwm.write(duty_cycle); |
bjornnijhuis | 1:68ca288dd6b5 | 19 | wait(3); |
bjornnijhuis | 0:dc1151db1e78 | 20 | } |
bjornnijhuis | 0:dc1151db1e78 | 21 | duty_cycle = 0; |
bjornnijhuis | 0:dc1151db1e78 | 22 | motor_pwm.write(duty_cycle); |
bjornnijhuis | 0:dc1151db1e78 | 23 | } |
bjornnijhuis | 0:dc1151db1e78 | 24 | } |