a
Dependencies: mbed LidarLitev2
Diff: rori.cpp
- Revision:
- 0:48dbc1f972f1
diff -r 000000000000 -r 48dbc1f972f1 rori.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rori.cpp Sun Sep 29 09:41:46 2019 +0000 @@ -0,0 +1,48 @@ +#include "rori.h" +#include "mbed.h" + +Serial s(USBTX,USBRX); +RORI::RORI(PinName a,PinName b): pinA(a),pinB(b),DigA(a),DigB(b){ + flag = true; + DigA.mode(PullDown); + DigB.mode(PullDown); + } + +void RORI::loli(){ + volatile short hear = DigA.read()<<1 | DigB.read(); + + s.printf("%d",DigA.read()); + s.printf("%s",":"); + s.printf("%d\n",DigB.read()); + + if(!dir){ + if(hear == 1){ + dir = hear; + }else if(hear == 2){ + dir = hear; + }else if(!hear){ + dir = 0; + } + }else if(!hear){ + if(old != dir){ + if(dir == 2){ + enc_count++; + }else if(dir == 1){ + enc_count--; + } + } + dir = 0; + } + old = hear; + } + + void RORI::read(long *a){ + pinA.rise(this,&RORI::loli); + pinA.fall(this,&RORI::loli); + pinB.rise(this,&RORI::loli); + pinB.fall(this,&RORI::loli); + *a = enc_count; + } +bool RORI::getflag(){ + return(flag); + } \ No newline at end of file