YMFC-AL implementation in mbed.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PPM.cpp Source File

PPM.cpp

00001 #include "mbed.h"
00002 #include "PPM.h"
00003  
00004 PPM::PPM(PinName pin): ppm(pin)
00005 {
00006     for (int i = 0; i < NUM_CHANNELS; i++)
00007         channels[i] = 1500;
00008     currentChannel = 0;    
00009     timer.start();
00010     ppm.rise( callback(this, &PPM::rise) );
00011 }
00012             
00013 void PPM::rise()
00014 {
00015     uint16_t time = timer.read_us();
00016     timer.reset();
00017     
00018     if ( time > 2500 )
00019     {
00020        currentChannel = 0;
00021     }
00022     else if ( currentChannel < NUM_CHANNELS )
00023     {
00024         channels[currentChannel] = time;
00025         currentChannel++;
00026     }
00027 }