Motor control

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
5:17aa878564d0
Parent:
4:e7d50c6a7c53
Child:
6:1c0b6e55e900
--- a/main.cpp	Fri Oct 11 12:18:08 2019 +0000
+++ b/main.cpp	Fri Oct 11 12:22:26 2019 +0000
@@ -25,6 +25,8 @@
 DigitalOut motor1Direction(D7);
 FastPWM motor1Power(D6);
 
+volatile int motor1Toggle = 1;
+
 //Motorcontrol
 bool motordir;
 double motorpwm;
@@ -107,7 +109,7 @@
         motordir= 0;}
     else {
          motordir= 1;}
-    motor1Power.pulsewidth(motorpwm * PWM_period );
+    motor1Power.pulsewidth(motorpwm * PWM_period*motor1Toggle );
     motor1Direction= motordir;
 }
 
@@ -120,7 +122,10 @@
     scope.send(); //send what's in scope memory to PC
 }
 
-
+void toggleMotor()
+{
+    motor1Toggle = !motor1Toggle;
+}
 
 int main()
 {
@@ -131,7 +136,8 @@
     motorTicker.attach(motorControl, 0.01);
     scopeTicker.attach(Plotje, 0.01);
     encoderTicker.attach(readEncoder, Ts);
-   
+    
+    button2.fall(&toggleMotor);
     while (true) {
 
         pc.printf("Potmeter: %d \r\n", potValue);