multipress example

Dependencies:   mbed

Committer:
kaushalpkk
Date:
Thu Jul 12 17:29:35 2018 +0000
Revision:
0:5a93e74b5fdf
commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kaushalpkk 0:5a93e74b5fdf 1 #include "mbed.h"
kaushalpkk 0:5a93e74b5fdf 2
kaushalpkk 0:5a93e74b5fdf 3 Timeout flipper;
kaushalpkk 0:5a93e74b5fdf 4 DigitalOut led1(LED1);
kaushalpkk 0:5a93e74b5fdf 5 DigitalOut led2(LED4);
kaushalpkk 0:5a93e74b5fdf 6 InterruptIn button(p14);
kaushalpkk 0:5a93e74b5fdf 7
kaushalpkk 0:5a93e74b5fdf 8 int count =0;
kaushalpkk 0:5a93e74b5fdf 9
kaushalpkk 0:5a93e74b5fdf 10 void flip()
kaushalpkk 0:5a93e74b5fdf 11 {
kaushalpkk 0:5a93e74b5fdf 12 if(count == 1) {
kaushalpkk 0:5a93e74b5fdf 13 printf("single press\n");
kaushalpkk 0:5a93e74b5fdf 14 } else if(count == 2) {
kaushalpkk 0:5a93e74b5fdf 15 printf("double press\n");
kaushalpkk 0:5a93e74b5fdf 16 } else {
kaushalpkk 0:5a93e74b5fdf 17 printf("multi press\n");
kaushalpkk 0:5a93e74b5fdf 18 }
kaushalpkk 0:5a93e74b5fdf 19 count = 0;
kaushalpkk 0:5a93e74b5fdf 20 }
kaushalpkk 0:5a93e74b5fdf 21
kaushalpkk 0:5a93e74b5fdf 22 void press()
kaushalpkk 0:5a93e74b5fdf 23 {
kaushalpkk 0:5a93e74b5fdf 24 printf(">\n");
kaushalpkk 0:5a93e74b5fdf 25 flipper.attach(&flip, 0.5);
kaushalpkk 0:5a93e74b5fdf 26 count++;
kaushalpkk 0:5a93e74b5fdf 27 }
kaushalpkk 0:5a93e74b5fdf 28
kaushalpkk 0:5a93e74b5fdf 29 int main(){
kaushalpkk 0:5a93e74b5fdf 30 printf("Hello world\n");
kaushalpkk 0:5a93e74b5fdf 31 button.rise(&press);
kaushalpkk 0:5a93e74b5fdf 32
kaushalpkk 0:5a93e74b5fdf 33 // spin in a main loop. flipper will interrupt it to call flip
kaushalpkk 0:5a93e74b5fdf 34 while(1) {
kaushalpkk 0:5a93e74b5fdf 35 led1 = !led1;
kaushalpkk 0:5a93e74b5fdf 36 wait(4);
kaushalpkk 0:5a93e74b5fdf 37 }
kaushalpkk 0:5a93e74b5fdf 38 }