decorder

Dependencies:   mbed QEI-1

Revision:
1:1e3eb2d1496b
Parent:
0:e63858fec119
Child:
2:af377291f3ae
--- a/main.cpp	Mon Apr 30 13:48:51 2018 +0000
+++ b/main.cpp	Wed May 02 08:01:38 2018 +0000
@@ -1,20 +1,59 @@
 #include "mbed.h"
 #include "QEI.h"
-Serial pc(PA_2, PA_3);
-PwmOut mypwm1(PB_7);
-PwmOut mypwm2(PB_6);
-QEI wheel(PB_10, PB_11, NC, 11, QEI::X4_ENCODING);
-int x;
-int main() {
-      
-    mypwm1.period_ms(2);
-    mypwm2.period_ms(2);
-    mypwm1.pulsewidth(0.001);
-    mypwm2.pulsewidth(0.001);
+DigitalOut w1(PB_6);
+DigitalOut w2(PB_7);
+DigitalOut w3(PB_8);
+DigitalOut w4(PB_9);
+PwmOut mypwm1(PA_9);
+PwmOut mypwm2(PA_8);
+Serial pc(PB_10, PB_11);
+Ticker toggle_time_ticker;
+QEI wheel(PA_2, PA_3, NC, 11, QEI::X4_ENCODING);
+QEI wheel2(PA_6, PA_7, NC, 11, QEI::X4_ENCODING);
+int x,y;
+float a= 0.01, b = 0.00860454;
+void time_ticker();
+void serialread();
+int main()
+{
+    mypwm1.period_ms(10);
+    mypwm2.period_ms(10);
+    toggle_time_ticker.attach(&time_ticker, 0.2);
+    pc.attach(&serialread);
+    mypwm1.pulsewidth(a);
+     mypwm2.pulsewidth(b);
+    wheel.reset();
+    wheel2.reset();
+    w1 = 0;
+  w2 = 0;
+    w3 = 0;
+    w4 = 0; 
     while(1)
     {
-      wait(0.1);
-      x = wheel.getPulses();
-        pc.printf("Pulses is: %i\n", x);
+        
     }   
 }
+
+void time_ticker(){
+    x = wheel.getPulses();
+    y = wheel2.getPulses();
+    wheel.reset();
+    wheel2.reset();
+  pc.printf("x:%d y:%d\n",x,y);
+}
+
+void serialread(){
+    switch (pc.getc())
+  {
+    case '1':
+          w1=0;
+          w4=0;
+        break;
+    case '2':
+            w1=1;
+          w4=1;
+        break;
+    default:
+        break;
+  }
+}
\ No newline at end of file