ちょっとかえた

Fork of encoder by ケンタ ミヤザキ

encoder2.cpp

Committer:
frute8
Date:
2018-03-27
Revision:
2:82a12d9f0bca

File content as of revision 2:82a12d9f0bca:

#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;
}