joe carter
/
nitrocarproject
main_programs/main2.h@2:a079de4fd5b9, 2010-08-20 (annotated)
- Committer:
- joe
- Date:
- Fri Aug 20 15:38:52 2010 +0000
- Revision:
- 2:a079de4fd5b9
- Parent:
- 0:960b355eaa84
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe | 0:960b355eaa84 | 1 | #include "mbed.h" |
joe | 0:960b355eaa84 | 2 | #include "Counter.h" |
joe | 0:960b355eaa84 | 3 | DigitalOut led1(LED1); |
joe | 0:960b355eaa84 | 4 | #define TICK_PERIOD 0.5 |
joe | 0:960b355eaa84 | 5 | Counter counter(p18); |
joe | 0:960b355eaa84 | 6 | |
joe | 0:960b355eaa84 | 7 | Ticker tick; |
joe | 0:960b355eaa84 | 8 | volatile int tick_active = 0; |
joe | 0:960b355eaa84 | 9 | |
joe | 0:960b355eaa84 | 10 | void dotick (void) { |
joe | 0:960b355eaa84 | 11 | tick_active = 1; |
joe | 0:960b355eaa84 | 12 | |
joe | 0:960b355eaa84 | 13 | } |
joe | 0:960b355eaa84 | 14 | float samples [2] = {0}; |
joe | 0:960b355eaa84 | 15 | int index2 = 0; |
joe | 0:960b355eaa84 | 16 | int start = 1; |
joe | 0:960b355eaa84 | 17 | |
joe | 0:960b355eaa84 | 18 | int rpm_counter=0; |
joe | 0:960b355eaa84 | 19 | int main() { |
joe | 0:960b355eaa84 | 20 | |
joe | 0:960b355eaa84 | 21 | tick.attach(dotick,0.5); |
joe | 0:960b355eaa84 | 22 | while (1) { |
joe | 0:960b355eaa84 | 23 | while (tick_active == 0) {} |
joe | 0:960b355eaa84 | 24 | rpm_counter = counter.read(); |
joe | 0:960b355eaa84 | 25 | counter.reset(); |
joe | 0:960b355eaa84 | 26 | |
joe | 0:960b355eaa84 | 27 | tick_active = 0; |
joe | 0:960b355eaa84 | 28 | samples[index2] = 120*rpm_counter; |
joe | 0:960b355eaa84 | 29 | index2++; |
joe | 0:960b355eaa84 | 30 | if (index2 >= 2) { |
joe | 0:960b355eaa84 | 31 | index2 = 0; |
joe | 0:960b355eaa84 | 32 | } |
joe | 0:960b355eaa84 | 33 | int i; |
joe | 0:960b355eaa84 | 34 | start = 1; |
joe | 0:960b355eaa84 | 35 | for (i=0; i<2; i++) { |
joe | 0:960b355eaa84 | 36 | if (samples[i] <180) { |
joe | 0:960b355eaa84 | 37 | start = 0; |
joe | 0:960b355eaa84 | 38 | } |
joe | 0:960b355eaa84 | 39 | } |
joe | 0:960b355eaa84 | 40 | if (start) { |
joe | 0:960b355eaa84 | 41 | led1 = !led1; |
joe | 0:960b355eaa84 | 42 | } |
joe | 0:960b355eaa84 | 43 | } |
joe | 0:960b355eaa84 | 44 | } |
joe | 0:960b355eaa84 | 45 |