Example for OneButton library.

Dependencies:   OneButton mbed

Files at this revision

API Documentation at this revision

Comitter:
jaup
Date:
Thu Sep 01 09:23:20 2016 +0000
Commit message:
frist

Changed in this revision

OneButton.lib Show annotated file Show diff for this revision Revisions of this file
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 44483f34a885 OneButton.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OneButton.lib	Thu Sep 01 09:23:20 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jaup/code/OneButton/#fdf67f893a5c
diff -r 000000000000 -r 44483f34a885 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 01 09:23:20 2016 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#include "OneButton.h"
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+OneButton btn1(PC_13);
+
+void pressed() {
+    pc.printf("pressed\r\n");
+}
+
+void click() {
+    pc.printf("click\r\n");
+}
+
+void double_click() {
+    pc.printf("double_click\r\n");
+}
+
+void long_start() {
+    pc.printf("long_start\r\n");
+}
+
+void long_hold() {
+    pc.printf("long_hold\r\n");
+}
+
+void long_stop() {
+    pc.printf("long_stop\r\n");
+}
+
+int main() {
+
+    btn1.attachClick(&click);
+    btn1.attachPress(&pressed);
+    btn1.attachDoubleClick(&double_click);
+    btn1.attachLongPressStart(&long_start);
+    btn1.attachDuringLongPress(&long_hold);
+    btn1.attachLongPressStop(&long_stop);
+
+    while(1) {
+
+        btn1.tick(); //loop
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 44483f34a885 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 01 09:23:20 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/2241e3a39974
\ No newline at end of file