Encoder program for K64F microcontroller with 64 bit confic

Dependencies:   MODSERIAL QEI mbed

Fork of Encoder_program by Robert van der Wal

main.cpp

Committer:
Wallie117
Date:
2015-09-23
Revision:
1:b9fb9ec8a9e6
Parent:
0:9b63614c20f3
Child:
2:3e6f179dfe7d

File content as of revision 1:b9fb9ec8a9e6:

#include "mbed.h"
#include "QEI.h"
#include "MODSERIAL.h"
 
Serial pc(USBTX, USBRX);
DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
PwmOut motor2speed(D5);
//Use X4 encoding.
//QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING);
//Use X2 encoding by default.
QEI wheel (D11, D12, NC, 64,QEI::X4_ENCODING);       // 
Ticker flipper;
 
 void flip() {
    motor2direction.write(0);
    for(int i=0;i<21; i++)
        { 
            wait(0.1);
            pc.printf("Pulses is: %i\n", (wheel.getPulses()/((64*131)/360)));
        }
}
 
int main() {
 flipper.attach(&flip, 2.0);
    while(1){
        motor2direction.write(1);
        motor2speed.write(0.2);
        wait(0.1);
        pc.printf("Pulses is: %i\n", (wheel.getPulses()/((64*131)/360)));
    }
 
}