amt102-vのライブラリです

Committer:
taisyou
Date:
Thu Feb 20 08:59:27 2020 +0000
Revision:
0:60d903b5752f
release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taisyou 0:60d903b5752f 1 #include "incenc.h"
taisyou 0:60d903b5752f 2 //Xは使いませええん!!なので4ピンでだいじょうぶでs
taisyou 0:60d903b5752f 3 incEnc::incEnc(PinName p1,PinName p2):A(p1), B(p2)
taisyou 0:60d903b5752f 4 {
taisyou 0:60d903b5752f 5 A.rise(&Ar_f);//関数に引数を入れてはいけない
taisyou 0:60d903b5752f 6 A.fall(&Af_f);
taisyou 0:60d903b5752f 7 B.rise(&Br_f);
taisyou 0:60d903b5752f 8 B.fall(&Bf_f);
taisyou 0:60d903b5752f 9 }
taisyou 0:60d903b5752f 10 incEnc incenc[enc_MAX]= {
taisyou 0:60d903b5752f 11 incEnc(PC_10,PC_9),
taisyou 0:60d903b5752f 12 incEnc(PC_3,PC_4)
taisyou 0:60d903b5752f 13 };
taisyou 0:60d903b5752f 14 void Ar_f()//引数なしにするために
taisyou 0:60d903b5752f 15 {
taisyou 0:60d903b5752f 16 Ar(incenc,enc_MAX);
taisyou 0:60d903b5752f 17 }
taisyou 0:60d903b5752f 18 void Af_f()
taisyou 0:60d903b5752f 19 {
taisyou 0:60d903b5752f 20 Af(incenc,enc_MAX);
taisyou 0:60d903b5752f 21 }
taisyou 0:60d903b5752f 22 void Br_f()
taisyou 0:60d903b5752f 23 {
taisyou 0:60d903b5752f 24 Br(incenc,enc_MAX);
taisyou 0:60d903b5752f 25 }
taisyou 0:60d903b5752f 26 void Bf_f()
taisyou 0:60d903b5752f 27 {
taisyou 0:60d903b5752f 28 Bf(incenc,enc_MAX);
taisyou 0:60d903b5752f 29 }
taisyou 0:60d903b5752f 30 void Ar(incEnc *e,uint8_t MAX)
taisyou 0:60d903b5752f 31 {
taisyou 0:60d903b5752f 32 for(int i=0; i<MAX; i++) {
taisyou 0:60d903b5752f 33 if(e[i].B==0)e[i].read_buf++;
taisyou 0:60d903b5752f 34 else e[i].read_buf--;
taisyou 0:60d903b5752f 35 e[i].degree=e[i].read_buf*360/8192;
taisyou 0:60d903b5752f 36 }
taisyou 0:60d903b5752f 37 }
taisyou 0:60d903b5752f 38 void Af(incEnc *e,uint8_t MAX)
taisyou 0:60d903b5752f 39 {
taisyou 0:60d903b5752f 40 for(int i=0; i<MAX; i++) {
taisyou 0:60d903b5752f 41 if(e[i].B==1)e[i].read_buf++;
taisyou 0:60d903b5752f 42 else e[i].read_buf--;
taisyou 0:60d903b5752f 43 e[i].degree=e[i].read_buf*360/8192;
taisyou 0:60d903b5752f 44 }
taisyou 0:60d903b5752f 45 }
taisyou 0:60d903b5752f 46 void Br(incEnc *e,uint8_t MAX)
taisyou 0:60d903b5752f 47 {
taisyou 0:60d903b5752f 48 for(int i=0; i<MAX; i++) {
taisyou 0:60d903b5752f 49 if(e[i].A==1)e[i].read_buf++;
taisyou 0:60d903b5752f 50 else e[i].read_buf--;
taisyou 0:60d903b5752f 51 e[i].degree=e[i].read_buf*360/8192;
taisyou 0:60d903b5752f 52 }
taisyou 0:60d903b5752f 53 }
taisyou 0:60d903b5752f 54 void Bf(incEnc *e,uint8_t MAX)
taisyou 0:60d903b5752f 55 {
taisyou 0:60d903b5752f 56 for(int i=0; i<MAX; i++) {
taisyou 0:60d903b5752f 57 if(e[i].A==0)e[i].read_buf++;
taisyou 0:60d903b5752f 58 else e[i].read_buf--;
taisyou 0:60d903b5752f 59 e[i].degree=e[i].read_buf*360/8192;
taisyou 0:60d903b5752f 60 }
taisyou 0:60d903b5752f 61 }