hige dura
/
counter
main.cpp@0:d266ed1f3d53, 2012-07-04 (annotated)
- Committer:
- higedura
- Date:
- Wed Jul 04 11:18:08 2012 +0000
- Revision:
- 0:d266ed1f3d53
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
higedura | 0:d266ed1f3d53 | 1 | #include "mbed.h" |
higedura | 0:d266ed1f3d53 | 2 | |
higedura | 0:d266ed1f3d53 | 3 | Serial pc(USBTX, USBRX); // tx, rx |
higedura | 0:d266ed1f3d53 | 4 | Timer t; |
higedura | 0:d266ed1f3d53 | 5 | DigitalOut led1(LED1); |
higedura | 0:d266ed1f3d53 | 6 | DigitalOut led2(LED2); |
higedura | 0:d266ed1f3d53 | 7 | DigitalOut led3(LED3); |
higedura | 0:d266ed1f3d53 | 8 | DigitalOut led4(LED4); |
higedura | 0:d266ed1f3d53 | 9 | DigitalOut start(p5); |
higedura | 0:d266ed1f3d53 | 10 | InterruptIn stop(p6); |
higedura | 0:d266ed1f3d53 | 11 | DigitalIn counter_start(p7); |
higedura | 0:d266ed1f3d53 | 12 | |
higedura | 0:d266ed1f3d53 | 13 | void counter(); |
higedura | 0:d266ed1f3d53 | 14 | |
higedura | 0:d266ed1f3d53 | 15 | int main() { |
higedura | 0:d266ed1f3d53 | 16 | |
higedura | 0:d266ed1f3d53 | 17 | start = 0; |
higedura | 0:d266ed1f3d53 | 18 | pc.baud(921600); |
higedura | 0:d266ed1f3d53 | 19 | |
higedura | 0:d266ed1f3d53 | 20 | led1 = 1; led2 = 1; led3 = 1; led4 = 1; |
higedura | 0:d266ed1f3d53 | 21 | wait(0.5); led4 = 0; |
higedura | 0:d266ed1f3d53 | 22 | wait(0.5); led3 = 0; |
higedura | 0:d266ed1f3d53 | 23 | wait(0.5); led2 = 0; |
higedura | 0:d266ed1f3d53 | 24 | wait(0.5); led1 = 0; |
higedura | 0:d266ed1f3d53 | 25 | wait(0.5); |
higedura | 0:d266ed1f3d53 | 26 | led1 = 1; led2 = 1; led3 = 1; led4 = 1; |
higedura | 0:d266ed1f3d53 | 27 | |
higedura | 0:d266ed1f3d53 | 28 | stop.rise(&counter); |
higedura | 0:d266ed1f3d53 | 29 | |
higedura | 0:d266ed1f3d53 | 30 | pc.printf("Push button!\r\n"); |
higedura | 0:d266ed1f3d53 | 31 | while( counter_start==0 ){} |
higedura | 0:d266ed1f3d53 | 32 | pc.printf("Counter starts!!\r\n"); |
higedura | 0:d266ed1f3d53 | 33 | start = 1; |
higedura | 0:d266ed1f3d53 | 34 | t.start(); |
higedura | 0:d266ed1f3d53 | 35 | |
higedura | 0:d266ed1f3d53 | 36 | while( start==1 ){} |
higedura | 0:d266ed1f3d53 | 37 | |
higedura | 0:d266ed1f3d53 | 38 | printf("The time was taken %f seconds\r\n", t.read()); |
higedura | 0:d266ed1f3d53 | 39 | |
higedura | 0:d266ed1f3d53 | 40 | } |
higedura | 0:d266ed1f3d53 | 41 | |
higedura | 0:d266ed1f3d53 | 42 | void counter() { |
higedura | 0:d266ed1f3d53 | 43 | t.stop(); |
higedura | 0:d266ed1f3d53 | 44 | start = 0; |
higedura | 0:d266ed1f3d53 | 45 | } |