Junichi Katsu
/
LineFollow1
ライントレーサテスト ロボット製作セミナー演習
main.cpp@0:36ef7eb55090, 2013-08-10 (annotated)
- Committer:
- jksoft
- Date:
- Sat Aug 10 03:51:18 2013 +0000
- Revision:
- 0:36ef7eb55090
Rev1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:36ef7eb55090 | 1 | #include "mbed.h" |
jksoft | 0:36ef7eb55090 | 2 | #include "TB6612.h" |
jksoft | 0:36ef7eb55090 | 3 | |
jksoft | 0:36ef7eb55090 | 4 | BusOut leds( LED1 , LED2 ); |
jksoft | 0:36ef7eb55090 | 5 | AnalogIn floor_sensor[] = { (p15) , (p16) , (p17) , (p18) }; |
jksoft | 0:36ef7eb55090 | 6 | TB6612 left(p21,p12,p11); |
jksoft | 0:36ef7eb55090 | 7 | TB6612 right(p22,p14,p13); |
jksoft | 0:36ef7eb55090 | 8 | DigitalIn sw(p29); |
jksoft | 0:36ef7eb55090 | 9 | |
jksoft | 0:36ef7eb55090 | 10 | int Sensor() |
jksoft | 0:36ef7eb55090 | 11 | { |
jksoft | 0:36ef7eb55090 | 12 | int ret = 0; |
jksoft | 0:36ef7eb55090 | 13 | if(floor_sensor[1].read_u16() > 10000) |
jksoft | 0:36ef7eb55090 | 14 | { |
jksoft | 0:36ef7eb55090 | 15 | ret |= 0x01; |
jksoft | 0:36ef7eb55090 | 16 | } |
jksoft | 0:36ef7eb55090 | 17 | if(floor_sensor[2].read_u16() > 10000) |
jksoft | 0:36ef7eb55090 | 18 | { |
jksoft | 0:36ef7eb55090 | 19 | ret |= 0x02; |
jksoft | 0:36ef7eb55090 | 20 | } |
jksoft | 0:36ef7eb55090 | 21 | |
jksoft | 0:36ef7eb55090 | 22 | return(ret); |
jksoft | 0:36ef7eb55090 | 23 | } |
jksoft | 0:36ef7eb55090 | 24 | |
jksoft | 0:36ef7eb55090 | 25 | int main() { |
jksoft | 0:36ef7eb55090 | 26 | |
jksoft | 0:36ef7eb55090 | 27 | sw.mode(PullUp); |
jksoft | 0:36ef7eb55090 | 28 | |
jksoft | 0:36ef7eb55090 | 29 | while(sw==1) |
jksoft | 0:36ef7eb55090 | 30 | { |
jksoft | 0:36ef7eb55090 | 31 | leds = Sensor(); |
jksoft | 0:36ef7eb55090 | 32 | } |
jksoft | 0:36ef7eb55090 | 33 | |
jksoft | 0:36ef7eb55090 | 34 | while(1) { |
jksoft | 0:36ef7eb55090 | 35 | int val = Sensor(); |
jksoft | 0:36ef7eb55090 | 36 | |
jksoft | 0:36ef7eb55090 | 37 | leds = val; |
jksoft | 0:36ef7eb55090 | 38 | |
jksoft | 0:36ef7eb55090 | 39 | switch(val) |
jksoft | 0:36ef7eb55090 | 40 | { |
jksoft | 0:36ef7eb55090 | 41 | case 0x01: |
jksoft | 0:36ef7eb55090 | 42 | left = 100; |
jksoft | 0:36ef7eb55090 | 43 | right = 0; |
jksoft | 0:36ef7eb55090 | 44 | break; |
jksoft | 0:36ef7eb55090 | 45 | case 0x02: |
jksoft | 0:36ef7eb55090 | 46 | right = 100; |
jksoft | 0:36ef7eb55090 | 47 | left = 0; |
jksoft | 0:36ef7eb55090 | 48 | break; |
jksoft | 0:36ef7eb55090 | 49 | case 0x03: |
jksoft | 0:36ef7eb55090 | 50 | left = 100; |
jksoft | 0:36ef7eb55090 | 51 | right = 100; |
jksoft | 0:36ef7eb55090 | 52 | break; |
jksoft | 0:36ef7eb55090 | 53 | default: |
jksoft | 0:36ef7eb55090 | 54 | left = 0; |
jksoft | 0:36ef7eb55090 | 55 | right = 0; |
jksoft | 0:36ef7eb55090 | 56 | break; |
jksoft | 0:36ef7eb55090 | 57 | } |
jksoft | 0:36ef7eb55090 | 58 | } |
jksoft | 0:36ef7eb55090 | 59 | } |