YMFC-AL implementation in mbed.

Dependencies:   mbed

PPM.cpp

Committer:
iforce2d
Date:
2019-10-04
Revision:
1:411d267f9d32

File content as of revision 1:411d267f9d32:

#include "mbed.h"
#include "PPM.h"
 
PPM::PPM(PinName pin): ppm(pin)
{
    for (int i = 0; i < NUM_CHANNELS; i++)
        channels[i] = 1500;
    currentChannel = 0;    
    timer.start();
    ppm.rise( callback(this, &PPM::rise) );
}
            
void PPM::rise()
{
    uint16_t time = timer.read_us();
    timer.reset();
    
    if ( time > 2500 )
    {
       currentChannel = 0;
    }
    else if ( currentChannel < NUM_CHANNELS )
    {
        channels[currentChannel] = time;
        currentChannel++;
    }
}