encoder
Embed:
(wiki syntax)
Show/hide line numbers
encoder01.cpp
00001 #include "mbed.h" 00002 #include "QEI.h" 00003 00004 QEI encoder1 (D14,D15,NC,2500); 00005 QEI encoder2 (D8,D9,NC,2500); 00006 QEI encoder3 (D4,D5,NC,2500); 00007 Serial pc(USBTX, USBRX); 00008 int counter1 = 0; 00009 int cur_state1 = 0; 00010 int counter2 = 0; 00011 int cur_state2 = 0; 00012 int counter3 = 0; 00013 int cur_state3 = 0; 00014 00015 int main(void) { 00016 while(1){ 00017 counter1 = encoder1.getPulses(); 00018 counter2 = encoder2.getPulses(); 00019 counter3 = encoder3.getPulses(); 00020 if( counter1 >= cur_state1){ 00021 cur_state1 = counter1; 00022 printf("1: %d ", cur_state1); 00023 }else if(counter1 < cur_state1){ 00024 cur_state1 = counter1; 00025 printf("1: %d ", cur_state1); 00026 }; 00027 00028 if( counter2 >= cur_state2){ 00029 cur_state2 = counter2; 00030 printf("2: %d ", cur_state2); 00031 }else if(counter2 < cur_state2){ 00032 cur_state2 = counter2; 00033 printf("2: %d ", cur_state2); 00034 }; 00035 00036 if( counter3 >= cur_state3){ 00037 cur_state3 = counter3; 00038 printf("3: %d ", cur_state3); 00039 }else if(counter3 < cur_state3){ 00040 cur_state3 = counter3; 00041 printf("3: %d ", cur_state3); 00042 } 00043 } 00044 }
Generated on Mon Aug 15 2022 22:14:56 by
1.7.2