Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:2d3d93d7b204, committed 2010-02-17
- Comitter:
- simon
- Date:
- Wed Feb 17 18:32:34 2010 +0000
- Child:
- 1:6d68eb9b6bbb
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Feb 17 18:32:34 2010 +0000
@@ -0,0 +1,49 @@
+// Example PwmIn class to detect PWM inputs, sford
+// - Note: uses InterruptIn, so not available on p19/p20
+
+#include "mbed.h"
+
+class PwmIn {
+public:
+ PwmIn(PinName p) : _p(p) {
+ _p.rise(this, &PwmIn::rise);
+ _p.fall(this, &PwmIn::fall);
+ _period = 0.0;
+ _pulsewidth = 0.0;
+ _t.start();
+ }
+
+ void rise() {
+ _period = _t.read();
+ _t.reset();
+ }
+
+ void fall() {
+ _pulsewidth = _t.read();
+ }
+
+ float period() { return _period; }
+ float pulsewidth() { return _pulsewidth; }
+ float dutycycle() { return _pulsewidth / _period; }
+
+protected:
+ InterruptIn _p;
+ Timer _t;
+ float _pulsewidth, _period;
+};
+
+PwmOut x(p21);
+PwmOut y(p22);
+
+PwmIn a(p5);
+PwmIn b(p6);
+
+int main() {
+ x = 0.5;
+ y = 0.2;
+ while(1) {
+ printf("a: pw = %f, period = %f\n", a.pulsewidth(), a.period());
+ printf("b: pw = %f, period = %f\n", b.pulsewidth(), b.period());
+ wait(2);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Feb 17 18:32:34 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0