Fork of encoder2 by Rikuto Fukunaga

encoder2.cpp

Committer:
kenken0721
Date:
2018-04-08
Revision:
3:03bca13f0bf6
Parent:
2:82a12d9f0bca

File content as of revision 3:03bca13f0bf6:

#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 = 1;
        count=0;
    }else zcount = 0;
  }else{
    count--;
    if(Z == true){
        zcount = 1;
        count=0;
    }else zcount = 0;
  }
}

int Encoder2::read_rotate(){
    return count;
}

int Encoder2::read_z(){
    return zcount;
}