Thijs Rakels / Mbed 2 deprecated Encoders

Dependencies:   mbed

Revision:
0:fb2b540167a8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Encoders.cpp	Tue Sep 25 15:48:29 2018 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include <math.h>
+
+
+DigitalOut Led1(D5);
+DigitalOut Led2(D4);
+DigitalIn  B(D2);
+DigitalIn  A(D3);
+Ticker check;
+Ticker printer;
+volatile int prev_A;
+volatile int prev_B;
+int state = 0;
+
+
+void Printer()
+{
+printf("%i\r\n",state);
+}
+
+
+void Checker ()
+{
+   if (prev_A == 1)
+   {
+       if(A == 0)
+       {
+       ++state;
+       }
+    }
+    if (prev_A == 0)
+   {
+       if(A == 1)
+       {
+       ++state;
+       }
+    }
+    prev_A = A;
+    
+    
+    if (prev_B == 1)
+   {
+       if(B == 0)
+       {
+       ++state;
+       }
+    }
+    if (prev_B == 0)
+   {
+       if(B == 1)
+       {
+       ++state;
+       }
+    }
+    prev_B = B;
+}
+
+
+
+
+main()
+{
+    printer.attach(Printer, 0.1);
+    check.attach(Checker, 1e-6);
+    prev_A = A;
+    prev_B = B;
+    while(true)
+    {
+    }     
+}
\ No newline at end of file