This is the encoder code

Dependencies:   mbed

main.cpp

Committer:
vceyssens3
Date:
2017-04-30
Revision:
0:ddf6b258e38a

File content as of revision 0:ddf6b258e38a:

#include "mbed.h"

DigitalOut myled(LED1);
InterruptIn encoder(p15);
Serial pc(USBTX, USBRX);
int ticker;

void ticker_func()
{
    ticker++;
    
}
int main() {
    
    encoder.mode(PullUp);
    encoder.fall(&ticker_func);
    encoder.rise(&ticker_func);
    double distance = 0;
    
    while(1) {
        myled=encoder;
        distance = double(ticker)*2.5/12;
        pc.printf("\r\n distance covered '%i'", ticker);
        wait(1);
        
    }
}