これは足をうごめかす何かです。
Dependencies: mbed
main.cpp@0:6ca09b29723e, 2014-09-16 (annotated)
- Committer:
- shiyuu
- Date:
- Tue Sep 16 09:31:13 2014 +0000
- Revision:
- 0:6ca09b29723e
?????byOguro
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shiyuu | 0:6ca09b29723e | 1 | /*send すいっちの簡単版*/ |
shiyuu | 0:6ca09b29723e | 2 | #include "mbed.h" |
shiyuu | 0:6ca09b29723e | 3 | AnalogIn aa(p19); |
shiyuu | 0:6ca09b29723e | 4 | AnalogIn bb(p17); |
shiyuu | 0:6ca09b29723e | 5 | //DigitalIn sw4[4]={p12,p13,p14,p15}; |
shiyuu | 0:6ca09b29723e | 6 | DigitalIn switch_on(p15); |
shiyuu | 0:6ca09b29723e | 7 | //DigitalIn switch_rt(p14); |
shiyuu | 0:6ca09b29723e | 8 | //DigitalIn switch_lu(p13); |
shiyuu | 0:6ca09b29723e | 9 | //DigitalIn switch_lt(p12); |
shiyuu | 0:6ca09b29723e | 10 | Serial pc(USBTX,USBRX); |
shiyuu | 0:6ca09b29723e | 11 | Serial Xbee (p28,p27);//p9, p10 |
shiyuu | 0:6ca09b29723e | 12 | void SetUp(void); |
shiyuu | 0:6ca09b29723e | 13 | |
shiyuu | 0:6ca09b29723e | 14 | void Setup(void){ |
shiyuu | 0:6ca09b29723e | 15 | /* |
shiyuu | 0:6ca09b29723e | 16 | sw4[0].mode(PullUp); |
shiyuu | 0:6ca09b29723e | 17 | sw4[1].mode(PullUp); |
shiyuu | 0:6ca09b29723e | 18 | sw4[2].mode(PullUp); |
shiyuu | 0:6ca09b29723e | 19 | sw4[3].mode(PullUp); |
shiyuu | 0:6ca09b29723e | 20 | */ |
shiyuu | 0:6ca09b29723e | 21 | |
shiyuu | 0:6ca09b29723e | 22 | switch_on.mode(PullUp); |
shiyuu | 0:6ca09b29723e | 23 | //switch_rt.mode(PullUp); |
shiyuu | 0:6ca09b29723e | 24 | //switch_lu.mode(PullUp); |
shiyuu | 0:6ca09b29723e | 25 | //switch_lt.mode(PullUp); |
shiyuu | 0:6ca09b29723e | 26 | |
shiyuu | 0:6ca09b29723e | 27 | uint8_t i=1; |
shiyuu | 0:6ca09b29723e | 28 | |
shiyuu | 0:6ca09b29723e | 29 | Xbee.putc(i); |
shiyuu | 0:6ca09b29723e | 30 | } |
shiyuu | 0:6ca09b29723e | 31 | |
shiyuu | 0:6ca09b29723e | 32 | int main() { |
shiyuu | 0:6ca09b29723e | 33 | |
shiyuu | 0:6ca09b29723e | 34 | unsigned int c1,c2; |
shiyuu | 0:6ca09b29723e | 35 | int data,rd,ld,swon; |
shiyuu | 0:6ca09b29723e | 36 | |
shiyuu | 0:6ca09b29723e | 37 | count=1; |
shiyuu | 0:6ca09b29723e | 38 | |
shiyuu | 0:6ca09b29723e | 39 | Setup(); |
shiyuu | 0:6ca09b29723e | 40 | |
shiyuu | 0:6ca09b29723e | 41 | c1=aa.read_u16(); //中央値 |
shiyuu | 0:6ca09b29723e | 42 | c2=bb.read_u16(); // |
shiyuu | 0:6ca09b29723e | 43 | |
shiyuu | 0:6ca09b29723e | 44 | while(1) { |
shiyuu | 0:6ca09b29723e | 45 | rd=ld=0; |
shiyuu | 0:6ca09b29723e | 46 | swon=0; |
shiyuu | 0:6ca09b29723e | 47 | |
shiyuu | 0:6ca09b29723e | 48 | /* LEFT */ |
shiyuu | 0:6ca09b29723e | 49 | |
shiyuu | 0:6ca09b29723e | 50 | if(bb.read_u16()>(c2*1.2)){ |
shiyuu | 0:6ca09b29723e | 51 | ld=0x80;//10000000 128 |
shiyuu | 0:6ca09b29723e | 52 | |
shiyuu | 0:6ca09b29723e | 53 | }else if((bb.read_u16() >= 0 )&&(bb.read_u16()<(c2 * 0.7))){ |
shiyuu | 0:6ca09b29723e | 54 | |
shiyuu | 0:6ca09b29723e | 55 | ld=0x40;//01000000 64 |
shiyuu | 0:6ca09b29723e | 56 | |
shiyuu | 0:6ca09b29723e | 57 | } |
shiyuu | 0:6ca09b29723e | 58 | |
shiyuu | 0:6ca09b29723e | 59 | /* RIGHT */ |
shiyuu | 0:6ca09b29723e | 60 | |
shiyuu | 0:6ca09b29723e | 61 | if(aa.read_u16()>(c1*1.2)){ |
shiyuu | 0:6ca09b29723e | 62 | rd=0x20;//00100000 32 |
shiyuu | 0:6ca09b29723e | 63 | |
shiyuu | 0:6ca09b29723e | 64 | }else if((aa.read_u16() >= 0 )&&(aa.read_u16()<(c1 * 0.7))){ |
shiyuu | 0:6ca09b29723e | 65 | |
shiyuu | 0:6ca09b29723e | 66 | rd=0x10;//00010000 16 |
shiyuu | 0:6ca09b29723e | 67 | |
shiyuu | 0:6ca09b29723e | 68 | } |
shiyuu | 0:6ca09b29723e | 69 | |
shiyuu | 0:6ca09b29723e | 70 | swon=!switch_on; |
shiyuu | 0:6ca09b29723e | 71 | |
shiyuu | 0:6ca09b29723e | 72 | /* |
shiyuu | 0:6ca09b29723e | 73 | swlu=!sw4[0]; |
shiyuu | 0:6ca09b29723e | 74 | swlt=!sw4[1]; |
shiyuu | 0:6ca09b29723e | 75 | swrt=!sw4[2]; |
shiyuu | 0:6ca09b29723e | 76 | swru=!sw4[3]; |
shiyuu | 0:6ca09b29723e | 77 | */ |
shiyuu | 0:6ca09b29723e | 78 | |
shiyuu | 0:6ca09b29723e | 79 | data=rd+ld+swon; // |
shiyuu | 0:6ca09b29723e | 80 | |
shiyuu | 0:6ca09b29723e | 81 | //pc.printf("%d\n",swon); |
shiyuu | 0:6ca09b29723e | 82 | pc.printf("%d\n",data); |
shiyuu | 0:6ca09b29723e | 83 | |
shiyuu | 0:6ca09b29723e | 84 | //pc.printf("%d %d %d %d\n",lt,lu,rt,ru); |
shiyuu | 0:6ca09b29723e | 85 | //pc.printf("%d\n",swrt); |
shiyuu | 0:6ca09b29723e | 86 | |
shiyuu | 0:6ca09b29723e | 87 | Xbee.putc(data); |
shiyuu | 0:6ca09b29723e | 88 | |
shiyuu | 0:6ca09b29723e | 89 | } |
shiyuu | 0:6ca09b29723e | 90 | } |