Used to read incoming PWM signals from RC channels
PulseIn.h@0:1a57c7f88422, 2012-12-19 (annotated)
- Committer:
- KarimAzzouz
- Date:
- Wed Dec 19 08:06:23 2012 +0000
- Revision:
- 0:1a57c7f88422
- Child:
- 1:eaf70ff4df07
Working !!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KarimAzzouz | 0:1a57c7f88422 | 1 | #ifndef RC_CHANNEL_H |
KarimAzzouz | 0:1a57c7f88422 | 2 | #define PULSEIN_H |
KarimAzzouz | 0:1a57c7f88422 | 3 | |
KarimAzzouz | 0:1a57c7f88422 | 4 | #include "mbed.h" |
KarimAzzouz | 0:1a57c7f88422 | 5 | |
KarimAzzouz | 0:1a57c7f88422 | 6 | class PulseIn |
KarimAzzouz | 0:1a57c7f88422 | 7 | { |
KarimAzzouz | 0:1a57c7f88422 | 8 | public: |
KarimAzzouz | 0:1a57c7f88422 | 9 | PulseIn(PinName p); |
KarimAzzouz | 0:1a57c7f88422 | 10 | int read(); // read the last measured data |
KarimAzzouz | 0:1a57c7f88422 | 11 | |
KarimAzzouz | 0:1a57c7f88422 | 12 | private: |
KarimAzzouz | 0:1a57c7f88422 | 13 | InterruptIn _k; // interrupt on the pin to react when signal falls or rises |
KarimAzzouz | 0:1a57c7f88422 | 14 | void rise(); // start the time measurement when signal rises |
KarimAzzouz | 0:1a57c7f88422 | 15 | void fall(); // stop the time mesurement and save the value when signal falls |
KarimAzzouz | 0:1a57c7f88422 | 16 | Timer t; // timer to measure the up time of the signal and if the signal timed out |
KarimAzzouz | 0:1a57c7f88422 | 17 | int _duration; // last measurement data |
KarimAzzouz | 0:1a57c7f88422 | 18 | }; |
KarimAzzouz | 0:1a57c7f88422 | 19 | |
KarimAzzouz | 0:1a57c7f88422 | 20 | #endif |
KarimAzzouz | 0:1a57c7f88422 | 21 |