NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

RC/RC_Channel.cpp

Committer:
maetugr
Date:
2012-10-29
Revision:
15:753c5d6a63b3
Parent:
12:67a06c9b69d5
Child:
20:e116e596e540

File content as of revision 15:753c5d6a63b3:

#include "RC_Channel.h"
#include "mbed.h"

RC_Channel::RC_Channel(PinName mypin) : myinterrupt(mypin)
{
    time = -1; // start value to see if there was any value yet
    myinterrupt.rise(this, &RC_Channel::rise);
    myinterrupt.fall(this, &RC_Channel::fall);
    timeoutchecker.attach(this, &RC_Channel::timeoutcheck, 1);
    
}

int RC_Channel::read()
{
    return time;
}

void RC_Channel::rise()
{
    timer.start();
}

void RC_Channel::fall()
{
    timer.stop();
    int tester = timer.read_us();
    if(tester >= 1000 && tester <=2000)
        time = tester;
    timer.reset();
    timer.start();
}

void RC_Channel::timeoutcheck()
{
    if (timer.read() > 0.3)
        time = 0;
}