![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
for 3 encoders
encoder.cpp@2:36b9ba5a34ff, 2021-10-31 (annotated)
- Committer:
- ea78anana
- Date:
- Sun Oct 31 09:43:58 2021 +0000
- Revision:
- 2:36b9ba5a34ff
- Parent:
- 0:4d7336a951bd
for 1 encoder
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ea78anana | 0:4d7336a951bd | 1 | #include "mbed.h" |
ea78anana | 0:4d7336a951bd | 2 | #include "QEI.h" |
ea78anana | 0:4d7336a951bd | 3 | |
ea78anana | 0:4d7336a951bd | 4 | QEI encoder (A0,A1,NC,2500); |
ea78anana | 0:4d7336a951bd | 5 | Serial pc(USBTX, USBRX); |
ea78anana | 0:4d7336a951bd | 6 | int counter = 0; |
ea78anana | 0:4d7336a951bd | 7 | int cur_state = 0; |
ea78anana | 0:4d7336a951bd | 8 | |
ea78anana | 0:4d7336a951bd | 9 | int main(void) { |
ea78anana | 0:4d7336a951bd | 10 | while(1){ |
ea78anana | 0:4d7336a951bd | 11 | counter = encoder.getPulses(); |
ea78anana | 0:4d7336a951bd | 12 | if( counter > cur_state){ |
ea78anana | 0:4d7336a951bd | 13 | cur_state = counter; |
ea78anana | 0:4d7336a951bd | 14 | printf("%d ", cur_state); |
ea78anana | 2:36b9ba5a34ff | 15 | }else if(counter < cur_state){ |
ea78anana | 2:36b9ba5a34ff | 16 | cur_state = counter; |
ea78anana | 2:36b9ba5a34ff | 17 | printf("%d ", cur_state); |
ea78anana | 2:36b9ba5a34ff | 18 | } |
ea78anana | 0:4d7336a951bd | 19 | } |
ea78anana | 0:4d7336a951bd | 20 | } |