ちょっとかえた

Fork of encoder by ケンタ ミヤザキ

Files at this revision

API Documentation at this revision

Comitter:
frute8
Date:
Tue Mar 27 03:45:26 2018 +0000
Parent:
1:6456080fa03b
Commit message:
a

Changed in this revision

encoder.cpp Show diff for this revision Revisions of this file
encoder.h Show diff for this revision Revisions of this file
encoder2.cpp Show annotated file Show diff for this revision Revisions of this file
encoder2.h Show annotated file Show diff for this revision Revisions of this file
--- a/encoder.cpp	Mon Mar 26 20:42:49 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#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++;
-        count=0;
-    }
-  }else{
-    count--;
-    if(Z == true){
-        zcount--;
-        count=0;
-    }
-  }
-}
-
-int Encoder::read_rotate(){
-    return count;
-}
-
-int Encoder::read_z(){
-    return zcount;
-}
-
-
--- a/encoder.h	Mon Mar 26 20:42:49 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef ENCODER_H
-#define ENCODER_H
-
-#include "mbed.h"
-
-class Encoder{
-public  :
-    Encoder(PinName APin, PinName BPin, PinName ZPin);
-    int read_rotate();
-    int read_z();
-    void init();
-private :
-    InterruptIn A;
-    DigitalIn B;
-    DigitalIn Z;
-    int count;
-    int zcount;
-    void flag();
-};
-
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder2.cpp	Tue Mar 27 03:45:26 2018 +0000
@@ -0,0 +1,38 @@
+#include "encoder2.h"
+#include "mbed.h"
+
+Encoder2::Encoder2(PinName APin, PinName BPin, PinName ZPin) : A(APin) , B(BPin) , Z(ZPin){
+    A.rise(this,&Encoder2::flag);
+    init();
+}
+
+void Encoder2::init(void){
+    count = 0;
+    zcount = 0;
+}
+
+void Encoder2::flag(void){
+  if(B == true){
+    count++;
+    if(Z == true){
+        zcount++;
+        count=0;
+    }
+  }else{
+    count--;
+    if(Z == true){
+        zcount--;
+        count=0;
+    }
+  }
+}
+
+int Encoder2::read_rotate(){
+    return count;
+}
+
+int Encoder2::read_z(){
+    return zcount;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder2.h	Tue Mar 27 03:45:26 2018 +0000
@@ -0,0 +1,22 @@
+#ifndef ENCODER_H2
+#define ENCODER_H2
+
+#include "mbed.h"
+
+class Encoder2{
+public  :
+    Encoder2(PinName APin, PinName BPin, PinName ZPin);
+    int read_rotate();
+    int read_z();
+    void init();
+private :
+    InterruptIn A;
+    DigitalIn B;
+    DigitalIn Z;
+    int count;
+    int zcount;
+    void flag();
+};
+
+#endif
+