Motor test

Dependencies:   mbed

Fork of motor_reverser by Björn Nijhuis

Revision:
0:b54c5342b074
--- /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