Used to read incoming PWM signals from RC channels
Diff: PulseIn.cpp
- Revision:
- 1:eaf70ff4df07
- Parent:
- 0:1a57c7f88422
- Child:
- 2:4abac72addb7
--- a/PulseIn.cpp Wed Dec 19 08:06:23 2012 +0000 +++ b/PulseIn.cpp Sun Dec 23 23:49:18 2012 +0000 @@ -8,21 +8,31 @@ _duration=0; } - + + int PulseIn::read() { return _duration; } + int PulseIn::getAngle(){ + + return 30*(1500-_duration)/500; // Scale (1000--->1500 and 1500--->2000) to +/- 30 degrees range + + } + void PulseIn::rise() -{ +{ t.start(); } void PulseIn::fall() { t.stop(); - _duration = t.read_us(); - t.reset(); + uint16_t test = t.read_us(); + if(test >= 1000 && test <=2000){ + _prev=_duration; + _duration = (_prev * (1.0 - 0.3) + (t.read_us() * 0.3)); // Filter Data + } + t.reset(); } - \ No newline at end of file