inoue hirohumi
/
line_counter_test
クロスラインを通過したらカウントする
main.cpp@3:aade65d7ae44, 2014-11-29 (annotated)
- Committer:
- iou16
- Date:
- Sat Nov 29 18:17:26 2014 +0000
- Revision:
- 3:aade65d7ae44
- Parent:
- 2:11e6cc53842f
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iou16 | 0:af0b7ccbbad8 | 1 | #include "mbed.h" |
iou16 | 0:af0b7ccbbad8 | 2 | #include "SerialHalfDuplex.h" |
iou16 | 0:af0b7ccbbad8 | 3 | |
iou16 | 3:aade65d7ae44 | 4 | #define LINE_TIMER_LIMIT 0.01 |
iou16 | 0:af0b7ccbbad8 | 5 | |
iou16 | 3:aade65d7ae44 | 6 | DigitalIn digi_sen_r(p14); |
iou16 | 3:aade65d7ae44 | 7 | AnalogIn ana_sen_r_outside(p17); |
iou16 | 3:aade65d7ae44 | 8 | AnalogIn ana_sen_r_inside(p16); |
iou16 | 3:aade65d7ae44 | 9 | AnalogIn ana_sen_l_inside(p15); |
iou16 | 3:aade65d7ae44 | 10 | AnalogIn ana_sen_l_outside(p18); |
iou16 | 3:aade65d7ae44 | 11 | DigitalIn digi_sen_l(p13); |
iou16 | 0:af0b7ccbbad8 | 12 | |
iou16 | 2:11e6cc53842f | 13 | Timer LineTimer; |
iou16 | 2:11e6cc53842f | 14 | |
iou16 | 3:aade65d7ae44 | 15 | Serial pc(USBTX, USBRX); |
iou16 | 3:aade65d7ae44 | 16 | |
iou16 | 3:aade65d7ae44 | 17 | void CountLine(void); |
iou16 | 3:aade65d7ae44 | 18 | void InitCountLine(void); |
iou16 | 3:aade65d7ae44 | 19 | |
iou16 | 3:aade65d7ae44 | 20 | int line_count = 0, old_digi_sen_l = 0; |
iou16 | 0:af0b7ccbbad8 | 21 | |
iou16 | 0:af0b7ccbbad8 | 22 | int main() { |
iou16 | 3:aade65d7ae44 | 23 | InitCountLine(); |
iou16 | 0:af0b7ccbbad8 | 24 | while(1) { |
iou16 | 3:aade65d7ae44 | 25 | CountLine(); |
iou16 | 3:aade65d7ae44 | 26 | pc.printf("line_count: %d\n", line_count); |
iou16 | 3:aade65d7ae44 | 27 | } |
iou16 | 3:aade65d7ae44 | 28 | } |
iou16 | 3:aade65d7ae44 | 29 | |
iou16 | 3:aade65d7ae44 | 30 | void InitCountLine(void) |
iou16 | 3:aade65d7ae44 | 31 | { |
iou16 | 3:aade65d7ae44 | 32 | line_count = 0; |
iou16 | 3:aade65d7ae44 | 33 | old_digi_sen_l = digi_sen_l; |
iou16 | 3:aade65d7ae44 | 34 | } |
iou16 | 3:aade65d7ae44 | 35 | |
iou16 | 3:aade65d7ae44 | 36 | void CountLine(void) |
iou16 | 3:aade65d7ae44 | 37 | { |
iou16 | 3:aade65d7ae44 | 38 | if ((digi_sen_l == 1)&&(old_digi_sen_l == 0)) LineTimer.start(); |
iou16 | 3:aade65d7ae44 | 39 | |
iou16 | 3:aade65d7ae44 | 40 | if ((digi_sen_l == 0)&&(old_digi_sen_l == 1)) { |
iou16 | 2:11e6cc53842f | 41 | LineTimer.stop(); |
iou16 | 3:aade65d7ae44 | 42 | if (LineTimer.read() > LINE_TIMER_LIMIT) line_count++; |
iou16 | 2:11e6cc53842f | 43 | LineTimer.reset(); |
iou16 | 2:11e6cc53842f | 44 | } |
iou16 | 1:e9c2a98ed41d | 45 | |
iou16 | 3:aade65d7ae44 | 46 | old_digi_sen_l = digi_sen_l; |
iou16 | 3:aade65d7ae44 | 47 | } |