Aukie Hooglugt / Mbed 2 deprecated BMT-M9_motorcontrol

Dependencies:   Encoder HIDScope MODSERIAL mbed-dsp mbed

Fork of BMT-M9_motorcontrol_groep3 by Aukie Hooglugt

Files at this revision

API Documentation at this revision

Comitter:
Hooglugt
Date:
Fri Oct 17 09:39:49 2014 +0000
Parent:
13:7ec4762ec4ce
Child:
15:979011e26ca3
Commit message:
aan/uit elke 5 sec toegevoegd

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 17 08:47:27 2014 +0000
+++ b/main.cpp	Fri Oct 17 09:39:49 2014 +0000
@@ -7,6 +7,7 @@
 void clamp(float * in, float min, float max);
 volatile bool looptimerflag;
 HIDScope scope(2);
+float new_pwm = 0;
 
 void setlooptimerflag(void)
 {
@@ -18,6 +19,16 @@
 *in > min ? *in < max? : *in = max: *in = min;
 }
 
+void looper()
+{
+    if (new_pwm==0) {
+        new_pwm = 1;
+    } else {
+        new_pwm = 0;
+    }
+}
+
+
 int main()
 {
     Encoder motor1(PTD2,PTD0);
@@ -26,27 +37,24 @@
     DigitalOut motordir(PTC9);
     Ticker looptimer;
     looptimer.attach(setlooptimerflag,TSAMP);
-    
-    wait(10);
+    Ticker flip_switch;
+    flip_switch.attach(looper, 5);
 
     while(1) {
-        float new_pwm;
-        
         while(!looptimerflag);
         looptimerflag = false; //clear flag
 
-        new_pwm = 1; 
         clamp(&new_pwm, -1,1);
 
         scope.set(0, new_pwm);
         scope.set(1, motor1.getPosition());
         scope.send();
-        
+
         if(new_pwm > 0)
             motordir = 0;
         else
             motordir = 1;
-            
+
         pwm_motor.write(abs(new_pwm));
     }
 }
\ No newline at end of file