Timer
Dependencies: mbed
main.cpp@0:5d80af5c7773, 2015-05-29 (annotated)
- Committer:
- VigneshRSR
- Date:
- Fri May 29 03:29:19 2015 +0000
- Revision:
- 0:5d80af5c7773
Timer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VigneshRSR | 0:5d80af5c7773 | 1 | #include "mbed.h" |
VigneshRSR | 0:5d80af5c7773 | 2 | |
VigneshRSR | 0:5d80af5c7773 | 3 | //------------------------------------ |
VigneshRSR | 0:5d80af5c7773 | 4 | // Hyperterminal configuration |
VigneshRSR | 0:5d80af5c7773 | 5 | // 9600 bauds, 8-bit data, no parity |
VigneshRSR | 0:5d80af5c7773 | 6 | //------------------------------------ |
VigneshRSR | 0:5d80af5c7773 | 7 | |
VigneshRSR | 0:5d80af5c7773 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
VigneshRSR | 0:5d80af5c7773 | 9 | |
VigneshRSR | 0:5d80af5c7773 | 10 | /*PwmOut mypwm(PWM_OUT); |
VigneshRSR | 0:5d80af5c7773 | 11 | DigitalOut myled(LED1);*/ |
VigneshRSR | 0:5d80af5c7773 | 12 | InterruptIn mybutton(USER_BUTTON); |
VigneshRSR | 0:5d80af5c7773 | 13 | |
VigneshRSR | 0:5d80af5c7773 | 14 | Timer t; |
VigneshRSR | 0:5d80af5c7773 | 15 | |
VigneshRSR | 0:5d80af5c7773 | 16 | int main() { |
VigneshRSR | 0:5d80af5c7773 | 17 | |
VigneshRSR | 0:5d80af5c7773 | 18 | int f = 0; |
VigneshRSR | 0:5d80af5c7773 | 19 | while(1) { |
VigneshRSR | 0:5d80af5c7773 | 20 | if (mybutton == 0) { |
VigneshRSR | 0:5d80af5c7773 | 21 | t.start(); |
VigneshRSR | 0:5d80af5c7773 | 22 | f = 1; |
VigneshRSR | 0:5d80af5c7773 | 23 | } |
VigneshRSR | 0:5d80af5c7773 | 24 | else if (f == 1 && mybutton == 1) { |
VigneshRSR | 0:5d80af5c7773 | 25 | t.stop(); |
VigneshRSR | 0:5d80af5c7773 | 26 | f = 0; |
VigneshRSR | 0:5d80af5c7773 | 27 | pc.printf("The time taken was %f seconds", t.read()); |
VigneshRSR | 0:5d80af5c7773 | 28 | t.reset(); |
VigneshRSR | 0:5d80af5c7773 | 29 | } |
VigneshRSR | 0:5d80af5c7773 | 30 | } |
VigneshRSR | 0:5d80af5c7773 | 31 | } |