Encoder program for K64F microcontroller with 64 bit confic
Dependencies: MODSERIAL QEI mbed
Fork of Encoder_program by
main.cpp@0:9b63614c20f3, 2015-09-23 (annotated)
- Committer:
- Wallie117
- Date:
- Wed Sep 23 09:35:07 2015 +0000
- Revision:
- 0:9b63614c20f3
- Child:
- 1:b9fb9ec8a9e6
Het motor draait en kan bepalen hoe vaak die heeft gedraaid
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wallie117 | 0:9b63614c20f3 | 1 | #include "mbed.h" |
Wallie117 | 0:9b63614c20f3 | 2 | #include "QEI.h" |
Wallie117 | 0:9b63614c20f3 | 3 | #include "MODSERIAL.h" |
Wallie117 | 0:9b63614c20f3 | 4 | |
Wallie117 | 0:9b63614c20f3 | 5 | Serial pc(USBTX, USBRX); |
Wallie117 | 0:9b63614c20f3 | 6 | DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield) |
Wallie117 | 0:9b63614c20f3 | 7 | PwmOut motor2speed(D5); |
Wallie117 | 0:9b63614c20f3 | 8 | //Use X4 encoding. |
Wallie117 | 0:9b63614c20f3 | 9 | //QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING); |
Wallie117 | 0:9b63614c20f3 | 10 | //Use X2 encoding by default. |
Wallie117 | 0:9b63614c20f3 | 11 | QEI wheel (D11, D12, NC, 64,QEI::X4_ENCODING); // |
Wallie117 | 0:9b63614c20f3 | 12 | |
Wallie117 | 0:9b63614c20f3 | 13 | int main() { |
Wallie117 | 0:9b63614c20f3 | 14 | |
Wallie117 | 0:9b63614c20f3 | 15 | while(1){ |
Wallie117 | 0:9b63614c20f3 | 16 | |
Wallie117 | 0:9b63614c20f3 | 17 | |
Wallie117 | 0:9b63614c20f3 | 18 | motor2direction.write(1); |
Wallie117 | 0:9b63614c20f3 | 19 | motor2speed.write(0.2); |
Wallie117 | 0:9b63614c20f3 | 20 | wait(0.1); |
Wallie117 | 0:9b63614c20f3 | 21 | pc.printf("Pulses is: %i\n", (wheel.getPulses()/(64*131))); |
Wallie117 | 0:9b63614c20f3 | 22 | } |
Wallie117 | 0:9b63614c20f3 | 23 | |
Wallie117 | 0:9b63614c20f3 | 24 | } |