Used to read incoming PWM signals from RC channels

Dependents:   A-Quad

RC.cpp

Committer:
KarimAzzouz
Date:
2013-08-27
Revision:
3:c98b23d53e42

File content as of revision 3:c98b23d53e42:

#include "RC.h"
 
RC::RC(PinName p) : _k(p)
{
    _k.mode(PullDown);
    _k.rise(this, &RC::rise);
    _k.fall(this, &RC::fall);
    _value=0;
    
}

int RC::read()
{  
   return _value;
}

 
void RC::rise()
{   
     t.start();
}
 
void RC::fall()
{
    t.stop();
    if(t.read_us()>=1000&&t.read_us()<=2000) _value = t.read_us();
    t.reset();
}