Björn Nijhuis
/
motor_reverser
Motor test
Revision 0:b54c5342b074, committed 2015-09-23
- Comitter:
- bjornnijhuis
- Date:
- Wed Sep 23 08:14:49 2015 +0000
- Commit message:
- Initial commit
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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 23 08:14:49 2015 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" +Ticker reverser; + +PwmOut motor_pwm(D5); +DigitalOut dir(D4); + +const int pwm_frequency = 10000; // PWM frequency +const float duty_cycle = 1; // Duty cycle (half speed) +bool direction = false; // Motor direction + +const float reverse_frequency = 0.25; // Reversion frequency +float reverse_period = 1/reverse_frequency; + +void dirswitch(){ + direction = !direction; // Reverse direction + dir.write(direction); // Sending direction to pin + } + +int main() +{ +reverser.attach(dirswitch, reverse_period); + +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){ + } + + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 23 08:14:49 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file