ちょっとかえた

Fork of encoder by ケンタ ミヤザキ

encoder.cpp

Committer:
kenken0721
Date:
2018-03-22
Revision:
0:0d6f91c4a794
Child:
1:6456080fa03b

File content as of revision 0:0d6f91c4a794:

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