encoder

Dependencies:   mbed

Revision:
2:92fd61600fa8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder01.cpp	Sun Oct 31 09:45:26 2021 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "QEI.h"
+
+QEI encoder1 (D14,D15,NC,2500);
+QEI encoder2 (D8,D9,NC,2500);
+QEI encoder3 (D4,D5,NC,2500);
+Serial pc(USBTX, USBRX);
+int counter1 = 0;
+int cur_state1 = 0;
+int counter2 = 0;
+int cur_state2 = 0;
+int counter3 = 0;
+int cur_state3 = 0;
+
+int main(void) {  
+        while(1){
+        counter1 = encoder1.getPulses();
+        counter2 = encoder2.getPulses();
+        counter3 = encoder3.getPulses();
+        if( counter1 >= cur_state1){
+            cur_state1 = counter1;
+            printf("1: %d ", cur_state1);
+            }else if(counter1 < cur_state1){
+                cur_state1 = counter1;
+                printf("1: %d ", cur_state1);
+                };
+                
+        if( counter2 >= cur_state2){
+            cur_state2 = counter2;
+            printf("2: %d ", cur_state2);
+            }else if(counter2 < cur_state2){
+                cur_state2 = counter2;
+                printf("2: %d ", cur_state2);
+                };
+                
+        if( counter3 >= cur_state3){
+            cur_state3 = counter3;
+            printf("3: %d ", cur_state3);
+            }else if(counter3 < cur_state3){
+                cur_state3 = counter3;
+                printf("3: %d ", cur_state3);
+                }              
+        }
+}
\ No newline at end of file