Sample program for MultiClick library.

Dependencies:   MultiClick mbed

Committer:
ohtsuka
Date:
Thu Jun 16 01:51:19 2016 +0000
Revision:
3:27aa2a2493e9
Parent:
2:918e95bf0abc
update MultiClick lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ohtsuka 2:918e95bf0abc 1 /*
ohtsuka 2:918e95bf0abc 2 MultiClick library sample program:
ohtsuka 2:918e95bf0abc 3 For one button operation.
ohtsuka 2:918e95bf0abc 4 This library suports these events,
ohtsuka 2:918e95bf0abc 5 * Single click
ohtsuka 2:918e95bf0abc 6 * Double click
ohtsuka 2:918e95bf0abc 7 * N times click (over 3 times click)
ohtsuka 2:918e95bf0abc 8 * Long press
ohtsuka 2:918e95bf0abc 9
ohtsuka 2:918e95bf0abc 10 The MIT License (MIT)
ohtsuka 2:918e95bf0abc 11
ohtsuka 2:918e95bf0abc 12 Copyright (c) 2016 Uematsu Electric Co.,Ltd. Toru OHTSUKA <t-ohtsuka@jupiter.ocn.ne.jp>
ohtsuka 2:918e95bf0abc 13
ohtsuka 2:918e95bf0abc 14 Permission is hereby granted, free of charge, to any person obtaining a copy
ohtsuka 2:918e95bf0abc 15 of this software and associated documentation files (the "Software"), to deal
ohtsuka 2:918e95bf0abc 16 in the Software without restriction, including without limitation the rights
ohtsuka 2:918e95bf0abc 17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ohtsuka 2:918e95bf0abc 18 copies of the Software, and to permit persons to whom the Software is
ohtsuka 2:918e95bf0abc 19 furnished to do so, subject to the following conditions:
ohtsuka 2:918e95bf0abc 20
ohtsuka 2:918e95bf0abc 21 The above copyright notice and this permission notice shall be included in
ohtsuka 2:918e95bf0abc 22 all copies or substantial portions of the Software.
ohtsuka 2:918e95bf0abc 23
ohtsuka 2:918e95bf0abc 24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ohtsuka 2:918e95bf0abc 25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ohtsuka 2:918e95bf0abc 26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ohtsuka 2:918e95bf0abc 27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ohtsuka 2:918e95bf0abc 28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ohtsuka 2:918e95bf0abc 29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ohtsuka 2:918e95bf0abc 30 THE SOFTWARE.
ohtsuka 2:918e95bf0abc 31 */
ohtsuka 2:918e95bf0abc 32
ohtsuka 0:6faa2b0370ff 33 #include "mbed.h"
ohtsuka 0:6faa2b0370ff 34 #include "MultiClick.h"
ohtsuka 0:6faa2b0370ff 35
ohtsuka 1:82989f872e3b 36 Serial pc(USBTX,USBRX);
ohtsuka 1:82989f872e3b 37
ohtsuka 0:6faa2b0370ff 38 DigitalOut myled(LED1);
ohtsuka 0:6faa2b0370ff 39
ohtsuka 0:6faa2b0370ff 40 MultiClick btn(dp24, PullUp);
ohtsuka 0:6faa2b0370ff 41
ohtsuka 0:6faa2b0370ff 42 void clicked(void){
ohtsuka 1:82989f872e3b 43 printf("\n********** single clicked.\n");
ohtsuka 0:6faa2b0370ff 44 }
ohtsuka 0:6faa2b0370ff 45
ohtsuka 0:6faa2b0370ff 46 void d_clicked(void){
ohtsuka 1:82989f872e3b 47 printf("\n********** double clicked.\n");
ohtsuka 0:6faa2b0370ff 48 }
ohtsuka 0:6faa2b0370ff 49
ohtsuka 0:6faa2b0370ff 50 void n_clicked(int times){
ohtsuka 1:82989f872e3b 51 printf("\n********** %d clicked.\n", times);
ohtsuka 1:82989f872e3b 52 }
ohtsuka 1:82989f872e3b 53
ohtsuka 1:82989f872e3b 54 void longpressed(void){
ohtsuka 1:82989f872e3b 55 printf("\n********** longpressed.\n");
ohtsuka 0:6faa2b0370ff 56 }
ohtsuka 0:6faa2b0370ff 57
ohtsuka 0:6faa2b0370ff 58 int main() {
ohtsuka 1:82989f872e3b 59 pc.baud(115200);
ohtsuka 1:82989f872e3b 60
ohtsuka 0:6faa2b0370ff 61 btn.attach_clicked(clicked);
ohtsuka 0:6faa2b0370ff 62 btn.attach_doubleclicked(d_clicked);
ohtsuka 0:6faa2b0370ff 63 btn.attach_n_clicked(n_clicked);
ohtsuka 1:82989f872e3b 64 btn.attach_longpressed(longpressed);
ohtsuka 0:6faa2b0370ff 65
ohtsuka 0:6faa2b0370ff 66 while(1) {
ohtsuka 0:6faa2b0370ff 67 myled = 1;
ohtsuka 0:6faa2b0370ff 68 wait(0.2);
ohtsuka 0:6faa2b0370ff 69 myled = 0;
ohtsuka 0:6faa2b0370ff 70 wait(0.2);
ohtsuka 0:6faa2b0370ff 71 }
ohtsuka 0:6faa2b0370ff 72 }