Example for OneButton library.

Dependencies:   OneButton mbed

Committer:
jaup
Date:
Thu Sep 01 09:23:20 2016 +0000
Revision:
0:44483f34a885
frist

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jaup 0:44483f34a885 1 #include "mbed.h"
jaup 0:44483f34a885 2 #include "OneButton.h"
jaup 0:44483f34a885 3
jaup 0:44483f34a885 4 Serial pc(SERIAL_TX, SERIAL_RX);
jaup 0:44483f34a885 5
jaup 0:44483f34a885 6 OneButton btn1(PC_13);
jaup 0:44483f34a885 7
jaup 0:44483f34a885 8 void pressed() {
jaup 0:44483f34a885 9 pc.printf("pressed\r\n");
jaup 0:44483f34a885 10 }
jaup 0:44483f34a885 11
jaup 0:44483f34a885 12 void click() {
jaup 0:44483f34a885 13 pc.printf("click\r\n");
jaup 0:44483f34a885 14 }
jaup 0:44483f34a885 15
jaup 0:44483f34a885 16 void double_click() {
jaup 0:44483f34a885 17 pc.printf("double_click\r\n");
jaup 0:44483f34a885 18 }
jaup 0:44483f34a885 19
jaup 0:44483f34a885 20 void long_start() {
jaup 0:44483f34a885 21 pc.printf("long_start\r\n");
jaup 0:44483f34a885 22 }
jaup 0:44483f34a885 23
jaup 0:44483f34a885 24 void long_hold() {
jaup 0:44483f34a885 25 pc.printf("long_hold\r\n");
jaup 0:44483f34a885 26 }
jaup 0:44483f34a885 27
jaup 0:44483f34a885 28 void long_stop() {
jaup 0:44483f34a885 29 pc.printf("long_stop\r\n");
jaup 0:44483f34a885 30 }
jaup 0:44483f34a885 31
jaup 0:44483f34a885 32 int main() {
jaup 0:44483f34a885 33
jaup 0:44483f34a885 34 btn1.attachClick(&click);
jaup 0:44483f34a885 35 btn1.attachPress(&pressed);
jaup 0:44483f34a885 36 btn1.attachDoubleClick(&double_click);
jaup 0:44483f34a885 37 btn1.attachLongPressStart(&long_start);
jaup 0:44483f34a885 38 btn1.attachDuringLongPress(&long_hold);
jaup 0:44483f34a885 39 btn1.attachLongPressStop(&long_stop);
jaup 0:44483f34a885 40
jaup 0:44483f34a885 41 while(1) {
jaup 0:44483f34a885 42
jaup 0:44483f34a885 43 btn1.tick(); //loop
jaup 0:44483f34a885 44 }
jaup 0:44483f34a885 45 }