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:
2:1e6dc5131b1b
Parent:
1:272adee7c4ac

File content as of revision 2:1e6dc5131b1b:

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

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