Example attaching a member function to a ticker

Dependencies:   mbed

mbed 2 and mbed OS 5

This is an mbed 2 example. For an mbed-os example, please see:

Import programTicker_Example

example creating a Ticker with callback

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Tue Feb 19 15:58:42 2013 +0000
Commit message:
First commit

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
diff -r 000000000000 -r 14eb5da7a9a3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 19 15:58:42 2013 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+ 
+// A class for flip()-ing a DigitalOut 
+class Flipper {
+public:
+    Flipper(PinName pin) : _pin(pin) {
+        _pin = 0;
+    }
+    void flip() {
+        _pin = !_pin;
+    }
+private:
+    DigitalOut _pin;
+};
+ 
+DigitalOut led1(LED1);
+Flipper f(LED2);
+Ticker t;
+ 
+int main() {
+    t.attach(&f, &Flipper::flip, 2.0); // the address of the object, member function, and interval
+ 
+    // spin in a main loop. flipper will interrupt it to call flip
+    while(1) {
+        led1 = !led1;
+        wait(0.2);
+    }
+}
diff -r 000000000000 -r 14eb5da7a9a3 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 19 15:58:42 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/3d0ef94e36ec
\ No newline at end of file