QEIx4 Example

Dependencies:   QEIx4 mbed

main.cpp

Committer:
jocis
Date:
2014-09-02
Revision:
0:bbf48777e304
Child:
2:7c787d83331e

File content as of revision 0:bbf48777e304:

#include "mbed.h"
#include "QEIx4.h"

DigitalOut myled(LED1);
Timer t;

// ports for nxp LPC 1768
QEIx4 qei1(p30, p29, p28);          // QEI with index signal for zeroing
QEIx4 qei2(p27, p26, NC);           // QEI only with AB signals
QEIx4 qei3(p25, p24, NC, false);    // QEI without interrups for polling mode

int main() {
    t.start();

    qei1.SetZeroOnIndex(true);      // Set the flag to zero counter on next index signal rises

    while(1) 
    {
        qei3.poll();   // poll manually without interrupt - sampling in this loop with about 2kHz
        
        if ( t.read_ms() > 500 )   // every half second
        {
            t.reset();
            t.start();
            myled = !myled;
            
            printf ( "\r\n%6d %6d %6d", (int)qei1, (int)qei2, (int)qei3 );   // print counter values
        }

    wait_us(500);   // for about 2kHz
    }
}