Dammenisvoorcasuals / Mbed 2 deprecated motor_reverser

Dependencies:   mbed

Fork of motor_reverser by Björn Nijhuis

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Ticker reverser;
00003 
00004 PwmOut motor_pwm(D5);
00005 DigitalOut dir(D4);
00006 
00007 const int pwm_frequency     = 10000;    // PWM frequency
00008 const float duty_cycle      = 1;      // Duty cycle (half speed)
00009 bool direction              = false;     // Motor direction
00010 
00011 const float reverse_frequency =  0.25;       // Reversion frequency
00012 float reverse_period          = 1/reverse_frequency;
00013 
00014 void dirswitch(){
00015     direction = !direction;             // Reverse direction
00016     dir.write(direction);               // Sending direction to pin
00017     }
00018 
00019 int main()
00020 {    
00021 reverser.attach(dirswitch, reverse_period);
00022 
00023 dir.write(direction);                   // Write motor direction
00024 motor_pwm.period(1/pwm_frequency);      // Motor PWM period
00025 motor_pwm.write(duty_cycle);            // Set motor speed
00026 
00027 while(true){
00028     }
00029 
00030 
00031 }