Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: nhk_2018_undercarry_test04 nhk_2018_undercarry_test08 nhk_2018_undercarry_test09 nhk_2018_undercarry_test10 ... more
encoder.cpp
- Committer:
- kenken0721
- Date:
- 2018-03-22
- Revision:
- 0:0d6f91c4a794
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;
}