![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A polled Quadrature encoder Class
main.cpp@0:7c16b1d2f01e, 2011-08-30 (annotated)
- Committer:
- jgnoss
- Date:
- Tue Aug 30 19:52:34 2011 +0000
- Revision:
- 0:7c16b1d2f01e
- Child:
- 1:72e6e124a7e6
Working example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jgnoss | 0:7c16b1d2f01e | 1 | #include "mbed.h" |
jgnoss | 0:7c16b1d2f01e | 2 | #include "PolledQEI.h" |
jgnoss | 0:7c16b1d2f01e | 3 | |
jgnoss | 0:7c16b1d2f01e | 4 | |
jgnoss | 0:7c16b1d2f01e | 5 | |
jgnoss | 0:7c16b1d2f01e | 6 | |
jgnoss | 0:7c16b1d2f01e | 7 | int main() { |
jgnoss | 0:7c16b1d2f01e | 8 | int oldEncPos = 0; |
jgnoss | 0:7c16b1d2f01e | 9 | int newEncPos = 0; |
jgnoss | 0:7c16b1d2f01e | 10 | |
jgnoss | 0:7c16b1d2f01e | 11 | DigitalOut led1( LED1 ); |
jgnoss | 0:7c16b1d2f01e | 12 | |
jgnoss | 0:7c16b1d2f01e | 13 | PolledQEI enc(p5, p6); |
jgnoss | 0:7c16b1d2f01e | 14 | enc.setSampleFrequency(10000); |
jgnoss | 0:7c16b1d2f01e | 15 | |
jgnoss | 0:7c16b1d2f01e | 16 | led1 = 1; |
jgnoss | 0:7c16b1d2f01e | 17 | |
jgnoss | 0:7c16b1d2f01e | 18 | |
jgnoss | 0:7c16b1d2f01e | 19 | while (1) { |
jgnoss | 0:7c16b1d2f01e | 20 | newEncPos = enc.pos(); |
jgnoss | 0:7c16b1d2f01e | 21 | if (oldEncPos != newEncPos ) { |
jgnoss | 0:7c16b1d2f01e | 22 | oldEncPos = newEncPos; |
jgnoss | 0:7c16b1d2f01e | 23 | led1 = !led1; |
jgnoss | 0:7c16b1d2f01e | 24 | } |
jgnoss | 0:7c16b1d2f01e | 25 | |
jgnoss | 0:7c16b1d2f01e | 26 | wait(0.01); |
jgnoss | 0:7c16b1d2f01e | 27 | } |
jgnoss | 0:7c16b1d2f01e | 28 | } |
jgnoss | 0:7c16b1d2f01e | 29 | |
jgnoss | 0:7c16b1d2f01e | 30 |