Push and hold button to start timer. Release button to print time that the button was held for.

Dependencies:   mbed

Fork of Timer_HelloWorld by mbed official

main.cpp

Committer:
jw2ee
Date:
2014-01-07
Revision:
1:272adee7c4ac
Parent:
0:27e1de20d3cb
Child:
2:1e6dc5131b1b

File content as of revision 1:272adee7c4ac:

#include "mbed.h"
 
DigitalIn button1(PTC3); //button for KL46Z
Timer t;

bool pushed = false;
 
int main() {
    while(true) {
        if(!button1 && !pushed) {
            t.start();
            printf("Timer Started\r\n");
            pushed = true;
        }
        else if(button1 && pushed) {
            t.stop();
            printf("The time taken was %f seconds\r\n", t.read());
            t.reset();
            pushed = false;
        }
    }
}