Dependents:   nhk_2018_undercarry_test04 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more

Committer:
kenken0721
Date:
Thu Mar 22 05:55:17 2018 +0000
Revision:
0:0d6f91c4a794

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenken0721 0:0d6f91c4a794 1 #include "encoder.h"
kenken0721 0:0d6f91c4a794 2 #include "mbed.h"
kenken0721 0:0d6f91c4a794 3
kenken0721 0:0d6f91c4a794 4 Encoder::Encoder(PinName APin, PinName BPin, PinName ZPin) : A(APin) , B(BPin) , Z(ZPin){
kenken0721 0:0d6f91c4a794 5 A.rise(this,&Encoder::flag);
kenken0721 0:0d6f91c4a794 6 init();
kenken0721 0:0d6f91c4a794 7 }
kenken0721 0:0d6f91c4a794 8
kenken0721 0:0d6f91c4a794 9 void Encoder::init(void){
kenken0721 0:0d6f91c4a794 10 count = 0;
kenken0721 0:0d6f91c4a794 11 zcount = 0;
kenken0721 0:0d6f91c4a794 12 }
kenken0721 0:0d6f91c4a794 13
kenken0721 0:0d6f91c4a794 14 void Encoder::flag(void){
kenken0721 0:0d6f91c4a794 15 if(B == true){
kenken0721 0:0d6f91c4a794 16 count++;
kenken0721 0:0d6f91c4a794 17 if(Z == true){
kenken0721 0:0d6f91c4a794 18 zcount++;
kenken0721 0:0d6f91c4a794 19 }
kenken0721 0:0d6f91c4a794 20 }else{
kenken0721 0:0d6f91c4a794 21 count--;
kenken0721 0:0d6f91c4a794 22 if(Z == true){
kenken0721 0:0d6f91c4a794 23 zcount--;
kenken0721 0:0d6f91c4a794 24 }
kenken0721 0:0d6f91c4a794 25 }
kenken0721 0:0d6f91c4a794 26 }
kenken0721 0:0d6f91c4a794 27
kenken0721 0:0d6f91c4a794 28 float Encoder::read_rotate(){
kenken0721 0:0d6f91c4a794 29 return (float)(count / 300.0);
kenken0721 0:0d6f91c4a794 30 }
kenken0721 0:0d6f91c4a794 31
kenken0721 0:0d6f91c4a794 32 int Encoder::read_z(){
kenken0721 0:0d6f91c4a794 33 return zcount;
kenken0721 0:0d6f91c4a794 34 }
kenken0721 0:0d6f91c4a794 35
kenken0721 0:0d6f91c4a794 36