Dependents:   nhk_2018_undercarry_test04 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more

Revision:
0:0d6f91c4a794
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder.cpp	Thu Mar 22 05:55:17 2018 +0000
@@ -0,0 +1,36 @@
+#include "encoder.h"
+#include "mbed.h"
+
+Encoder::Encoder(PinName APin, PinName BPin, PinName ZPin) : A(APin) , B(BPin) , Z(ZPin){
+    A.rise(this,&Encoder::flag);
+    init();
+}
+
+void Encoder::init(void){
+    count = 0;
+    zcount = 0;
+}
+
+void Encoder::flag(void){
+  if(B == true){
+    count++;
+    if(Z == true){
+        zcount++;
+    }
+  }else{
+    count--;
+    if(Z == true){
+        zcount--;
+    }
+  }
+}
+
+float Encoder::read_rotate(){
+    return (float)(count / 300.0);
+}
+
+int Encoder::read_z(){
+    return zcount;
+}
+
+