QEIx4 Example

Dependencies:   QEIx4 mbed

Revision:
0:bbf48777e304
Child:
2:7c787d83331e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Sep 02 18:24:13 2014 +0000
@@ -0,0 +1,32 @@
+#include "mbed.h"
+#include "QEIx4.h"
+
+DigitalOut myled(LED1);
+Timer t;
+
+// ports for nxp LPC 1768
+QEIx4 qei1(p30, p29, p28);          // QEI with index signal for zeroing
+QEIx4 qei2(p27, p26, NC);           // QEI only with AB signals
+QEIx4 qei3(p25, p24, NC, false);    // QEI without interrups for polling mode
+
+int main() {
+    t.start();
+
+    qei1.SetZeroOnIndex(true);      // Set the flag to zero counter on next index signal rises
+
+    while(1) 
+    {
+        qei3.poll();   // poll manually without interrupt - sampling in this loop with about 2kHz
+        
+        if ( t.read_ms() > 500 )   // every half second
+        {
+            t.reset();
+            t.start();
+            myled = !myled;
+            
+            printf ( "\r\n%6d %6d %6d", (int)qei1, (int)qei2, (int)qei3 );   // print counter values
+        }
+
+    wait_us(500);   // for about 2kHz
+    }
+}