Used to read incoming PWM signals from RC channels

Dependents:   A-Quad

Files at this revision

API Documentation at this revision

Comitter:
KarimAzzouz
Date:
Tue Aug 27 09:32:34 2013 +0000
Parent:
2:4abac72addb7
Commit message:
initial commit

Changed in this revision

PulseIn.cpp Show diff for this revision Revisions of this file
PulseIn.h Show diff for this revision Revisions of this file
RC.cpp Show annotated file Show diff for this revision Revisions of this file
RC.h Show annotated file Show diff for this revision Revisions of this file
diff -r 4abac72addb7 -r c98b23d53e42 PulseIn.cpp
--- a/PulseIn.cpp	Tue Jan 08 15:01:22 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#include "PulseIn.h"
- 
-PulseIn::PulseIn(PinName p) : _k(p)
-{
-    _k.mode(PullDown);
-    _k.rise(this, &PulseIn::rise);
-    _k.fall(this, &PulseIn::fall);
-    _duration=0;
-    
-}
-
-int PulseIn::read()
-{
-    return _duration;
-}
- 
- 
-void PulseIn::rise()
-{   
-    t.start();
-}
- 
-void PulseIn::fall()
-{
-    t.stop();
-    _duration = t.read_us();
-    t.reset(); 
-}
diff -r 4abac72addb7 -r c98b23d53e42 PulseIn.h
--- a/PulseIn.h	Tue Jan 08 15:01:22 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#ifndef PULSEIN_H
-#define PULSEIN_H
- 
-#include "mbed.h"
- 
-class PulseIn
-{
-    public:
-        PulseIn(PinName p);
-        int read(void); 
-       
-    private:
-        InterruptIn _k; 
-        void rise(void); 
-        void fall(void); 
-        Timer t; 
-        uint16_t _duration; 
-};
- 
-#endif
-            
diff -r 4abac72addb7 -r c98b23d53e42 RC.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RC.cpp	Tue Aug 27 09:32:34 2013 +0000
@@ -0,0 +1,29 @@
+#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();
+}
+
diff -r 4abac72addb7 -r c98b23d53e42 RC.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RC.h	Tue Aug 27 09:32:34 2013 +0000
@@ -0,0 +1,24 @@
+#ifndef RC_H
+#define RC_H
+
+#include "mbed.h"
+ 
+class RC
+{
+    public:
+        RC(PinName p);
+        int read(void);
+       
+    private:
+         
+        void rise(void); 
+        void fall(void); 
+        
+        InterruptIn _k;
+        Timer t; 
+        volatile uint16_t _value;
+
+};
+ 
+#endif
+