足上げセンサ八個版仮
Dependencies: mbed
Fork of 4LegUpDown_8sense by
main.cpp@6:6664c6aa67d3, 2014-09-11 (annotated)
- Committer:
- ryuna
- Date:
- Thu Sep 11 22:00:53 2014 +0000
- Revision:
- 6:6664c6aa67d3
- Parent:
- 5:aba9f5e97e03
- Child:
- 7:583ad8798bf1
???????????????????????????????; ????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryuna | 0:76ba33d3b4a6 | 1 | #include "mbed.h" |
ryuna | 0:76ba33d3b4a6 | 2 | |
ryuna | 3:cd7d3613e8e4 | 3 | #define MOTOR_NUM 8 |
ryuna | 6:6664c6aa67d3 | 4 | #define MOVE_TIME 0.080 |
ryuna | 6:6664c6aa67d3 | 5 | #define MOVE_DOWN_TIME 0.090 |
ryuna | 6:6664c6aa67d3 | 6 | #define TEMPRA_TIME 5.0 |
ryuna | 3:cd7d3613e8e4 | 7 | #define PWM_LEVEL 1.0 |
ryuna | 0:76ba33d3b4a6 | 8 | |
ryuna | 0:76ba33d3b4a6 | 9 | Serial pc(USBTX,USBRX); |
ryuna | 0:76ba33d3b4a6 | 10 | |
ryuna | 3:cd7d3613e8e4 | 11 | InterruptIn Photo[8] = {p5,p6,p7,p8,p9,p10,p11,p12}; |
ryuna | 6:6664c6aa67d3 | 12 | //InterruptIn Sw(NC); |
ryuna | 3:cd7d3613e8e4 | 13 | |
ryuna | 1:807091115672 | 14 | |
ryuna | 3:cd7d3613e8e4 | 15 | DigitalOut Led[4] = {LED1, LED2, LED3, LED4 }; |
ryuna | 3:cd7d3613e8e4 | 16 | BusOut Motor(p13, p14, p15, p16, p17, p18, p19, p20 );//{left front, right front, left back ,right back } |
ryuna | 4:04f2479b83c1 | 17 | BusOut Tempra(p25,p26,p27,p28); |
ryuna | 4:04f2479b83c1 | 18 | PwmOut Pwm[4] = {p21, p22, p23, p24 }; |
ryuna | 1:807091115672 | 19 | |
ryuna | 3:cd7d3613e8e4 | 20 | Timeout StopTimer[8]; |
ryuna | 6:6664c6aa67d3 | 21 | Timeout StopTempra; |
ryuna | 4:04f2479b83c1 | 22 | //Timeout StopTempra; |
ryuna | 0:76ba33d3b4a6 | 23 | |
ryuna | 3:cd7d3613e8e4 | 24 | |
ryuna | 3:cd7d3613e8e4 | 25 | volatile bool MotorState[4] = {0},Flag[4] = {0},FlagAdd[4] = {0},And[4] = {0}; |
ryuna | 3:cd7d3613e8e4 | 26 | volatile uint8_t Way = 0,UpCt = 0; |
ryuna | 6:6664c6aa67d3 | 27 | volatile bool TempraFlag = 0; |
ryuna | 0:76ba33d3b4a6 | 28 | |
ryuna | 6:6664c6aa67d3 | 29 | /*motorstate 上がっているか下がっているか |
ryuna | 5:aba9f5e97e03 | 30 | |
ryuna | 1:807091115672 | 31 | |
ryuna | 3:cd7d3613e8e4 | 32 | */ |
ryuna | 3:cd7d3613e8e4 | 33 | |
ryuna | 1:807091115672 | 34 | /* |
ryuna | 1:807091115672 | 35 | bMotor = { |
ryuna | 1:807091115672 | 36 | LeftFrontUp, LeftFrontDown, |
ryuna | 1:807091115672 | 37 | RightFrontUp, RightFrontDown, |
ryuna | 1:807091115672 | 38 | LeftBackUp, LeftBackDown, |
ryuna | 1:807091115672 | 39 | RightBackUp, RightBackDown |
ryuna | 1:807091115672 | 40 | }; |
ryuna | 1:807091115672 | 41 | */ |
ryuna | 1:807091115672 | 42 | |
ryuna | 3:cd7d3613e8e4 | 43 | |
ryuna | 3:cd7d3613e8e4 | 44 | |
ryuna | 3:cd7d3613e8e4 | 45 | void MotorStop0(){ |
ryuna | 3:cd7d3613e8e4 | 46 | |
ryuna | 3:cd7d3613e8e4 | 47 | Motor = Motor & 0x7F; |
ryuna | 3:cd7d3613e8e4 | 48 | |
ryuna | 3:cd7d3613e8e4 | 49 | } |
ryuna | 3:cd7d3613e8e4 | 50 | void MotorStop1(){ |
ryuna | 3:cd7d3613e8e4 | 51 | |
ryuna | 3:cd7d3613e8e4 | 52 | Motor = Motor & 0xBF; |
ryuna | 3:cd7d3613e8e4 | 53 | |
ryuna | 3:cd7d3613e8e4 | 54 | } |
ryuna | 3:cd7d3613e8e4 | 55 | |
ryuna | 3:cd7d3613e8e4 | 56 | void MotorStop2(){ |
ryuna | 3:cd7d3613e8e4 | 57 | |
ryuna | 3:cd7d3613e8e4 | 58 | Motor = Motor & 0xF7; |
ryuna | 3:cd7d3613e8e4 | 59 | |
ryuna | 3:cd7d3613e8e4 | 60 | } |
ryuna | 3:cd7d3613e8e4 | 61 | void MotorStop3(){ |
ryuna | 3:cd7d3613e8e4 | 62 | |
ryuna | 3:cd7d3613e8e4 | 63 | Motor = Motor & 0xFB; |
ryuna | 3:cd7d3613e8e4 | 64 | |
ryuna | 3:cd7d3613e8e4 | 65 | } |
ryuna | 3:cd7d3613e8e4 | 66 | void MotorStop4(){ |
ryuna | 3:cd7d3613e8e4 | 67 | |
ryuna | 3:cd7d3613e8e4 | 68 | Motor = Motor & 0xDF; |
ryuna | 3:cd7d3613e8e4 | 69 | |
ryuna | 3:cd7d3613e8e4 | 70 | } |
ryuna | 3:cd7d3613e8e4 | 71 | void MotorStop5(){ |
ryuna | 3:cd7d3613e8e4 | 72 | |
ryuna | 3:cd7d3613e8e4 | 73 | Motor = Motor & 0xEF; |
ryuna | 3:cd7d3613e8e4 | 74 | |
ryuna | 3:cd7d3613e8e4 | 75 | } |
ryuna | 3:cd7d3613e8e4 | 76 | void MotorStop6(){ |
ryuna | 3:cd7d3613e8e4 | 77 | |
ryuna | 3:cd7d3613e8e4 | 78 | Motor = Motor & 0xFD; |
ryuna | 3:cd7d3613e8e4 | 79 | |
ryuna | 3:cd7d3613e8e4 | 80 | } |
ryuna | 3:cd7d3613e8e4 | 81 | void MotorStop7(){ |
ryuna | 3:cd7d3613e8e4 | 82 | |
ryuna | 3:cd7d3613e8e4 | 83 | Motor = Motor & 0xFE; |
ryuna | 3:cd7d3613e8e4 | 84 | |
ryuna | 3:cd7d3613e8e4 | 85 | } |
ryuna | 3:cd7d3613e8e4 | 86 | void TempraStop(){ |
ryuna | 6:6664c6aa67d3 | 87 | Tempra = 0x00; |
ryuna | 3:cd7d3613e8e4 | 88 | |
ryuna | 3:cd7d3613e8e4 | 89 | } |
ryuna | 3:cd7d3613e8e4 | 90 | void FallPhoto0(){//zero |
ryuna | 3:cd7d3613e8e4 | 91 | //Wayの決定 |
ryuna | 3:cd7d3613e8e4 | 92 | if(Way == 0){ |
ryuna | 3:cd7d3613e8e4 | 93 | Way = 1; |
ryuna | 3:cd7d3613e8e4 | 94 | } |
ryuna | 3:cd7d3613e8e4 | 95 | |
ryuna | 3:cd7d3613e8e4 | 96 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 97 | if(!MotorState[0]){ |
ryuna | 3:cd7d3613e8e4 | 98 | |
ryuna | 3:cd7d3613e8e4 | 99 | StopTimer[0].attach(&MotorStop0,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 100 | Motor = Motor | 0x80;//10000000 |
ryuna | 3:cd7d3613e8e4 | 101 | MotorState[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 102 | Led[0]= 1; |
ryuna | 3:cd7d3613e8e4 | 103 | }else{ |
ryuna | 3:cd7d3613e8e4 | 104 | Flag[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 105 | } |
ryuna | 6:6664c6aa67d3 | 106 | }/*else if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 107 | |
ryuna | 3:cd7d3613e8e4 | 108 | if(Flag[0]&&!FlagAdd[0]){ |
ryuna | 3:cd7d3613e8e4 | 109 | FlagAdd[0] = 1; |
ryuna | 5:aba9f5e97e03 | 110 | }else if(MotorState[0]){ |
ryuna | 3:cd7d3613e8e4 | 111 | StopTimer[1].attach(&MotorStop1,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 112 | Motor = Motor | 0x40;//0x40 = 01000000 |
ryuna | 3:cd7d3613e8e4 | 113 | MotorState[0] = 0; |
ryuna | 3:cd7d3613e8e4 | 114 | Flag[0] = 0; |
ryuna | 3:cd7d3613e8e4 | 115 | Led[0] = 0; |
ryuna | 3:cd7d3613e8e4 | 116 | And[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 117 | |
ryuna | 3:cd7d3613e8e4 | 118 | } |
ryuna | 6:6664c6aa67d3 | 119 | }*/ |
ryuna | 3:cd7d3613e8e4 | 120 | } |
ryuna | 3:cd7d3613e8e4 | 121 | |
ryuna | 3:cd7d3613e8e4 | 122 | void FallPhoto1(){//one |
ryuna | 3:cd7d3613e8e4 | 123 | //Wayの決定 |
ryuna | 6:6664c6aa67d3 | 124 | /*if(Way ==0){ |
ryuna | 3:cd7d3613e8e4 | 125 | Way = 2; |
ryuna | 6:6664c6aa67d3 | 126 | }*/ |
ryuna | 3:cd7d3613e8e4 | 127 | |
ryuna | 6:6664c6aa67d3 | 128 | /*if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 129 | if(!MotorState[0]){ |
ryuna | 3:cd7d3613e8e4 | 130 | |
ryuna | 3:cd7d3613e8e4 | 131 | StopTimer[0].attach(&MotorStop0,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 132 | Motor = Motor | 0x80;//10000000 |
ryuna | 3:cd7d3613e8e4 | 133 | MotorState[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 134 | Led[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 135 | }else{ |
ryuna | 3:cd7d3613e8e4 | 136 | Flag[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 137 | } |
ryuna | 6:6664c6aa67d3 | 138 | }else */ |
ryuna | 6:6664c6aa67d3 | 139 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 140 | |
ryuna | 3:cd7d3613e8e4 | 141 | if(Flag[0]&&!FlagAdd[0]){ |
ryuna | 3:cd7d3613e8e4 | 142 | FlagAdd[0] = 1; |
ryuna | 5:aba9f5e97e03 | 143 | }else if(MotorState[0]) { |
ryuna | 3:cd7d3613e8e4 | 144 | StopTimer[1].attach(&MotorStop1,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 145 | Motor = Motor | 0x40;//0x40 = 01000000 |
ryuna | 3:cd7d3613e8e4 | 146 | MotorState[0] = 0; |
ryuna | 3:cd7d3613e8e4 | 147 | Flag[0] = 0; |
ryuna | 6:6664c6aa67d3 | 148 | FlagAdd[0] = 0; |
ryuna | 3:cd7d3613e8e4 | 149 | Led[0] = 0; |
ryuna | 3:cd7d3613e8e4 | 150 | And[0] = 1; |
ryuna | 3:cd7d3613e8e4 | 151 | |
ryuna | 3:cd7d3613e8e4 | 152 | } |
ryuna | 3:cd7d3613e8e4 | 153 | } |
ryuna | 3:cd7d3613e8e4 | 154 | |
ryuna | 3:cd7d3613e8e4 | 155 | } |
ryuna | 3:cd7d3613e8e4 | 156 | void FallPhoto2(){//two |
ryuna | 3:cd7d3613e8e4 | 157 | //Wayの決定 |
ryuna | 3:cd7d3613e8e4 | 158 | |
ryuna | 3:cd7d3613e8e4 | 159 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 160 | if(!MotorState[1]){ |
ryuna | 3:cd7d3613e8e4 | 161 | |
ryuna | 3:cd7d3613e8e4 | 162 | StopTimer[2].attach(&MotorStop2,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 163 | Motor = Motor | 0x08; |
ryuna | 3:cd7d3613e8e4 | 164 | MotorState[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 165 | Led[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 166 | }else{ |
ryuna | 3:cd7d3613e8e4 | 167 | Flag[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 168 | } |
ryuna | 6:6664c6aa67d3 | 169 | }/*else if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 170 | |
ryuna | 3:cd7d3613e8e4 | 171 | if(Flag[1]&&!FlagAdd[1]){ |
ryuna | 3:cd7d3613e8e4 | 172 | FlagAdd[1] = 1; |
ryuna | 5:aba9f5e97e03 | 173 | }else if(MotorState[1]){ |
ryuna | 3:cd7d3613e8e4 | 174 | StopTimer[3].attach(&MotorStop3,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 175 | Motor = Motor | 0x04; |
ryuna | 3:cd7d3613e8e4 | 176 | MotorState[1] = 0; |
ryuna | 3:cd7d3613e8e4 | 177 | Flag[1] = 0; |
ryuna | 3:cd7d3613e8e4 | 178 | Led[1] = 0; |
ryuna | 3:cd7d3613e8e4 | 179 | And[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 180 | } |
ryuna | 6:6664c6aa67d3 | 181 | } */ |
ryuna | 3:cd7d3613e8e4 | 182 | |
ryuna | 3:cd7d3613e8e4 | 183 | } |
ryuna | 3:cd7d3613e8e4 | 184 | void FallPhoto3(){ //three |
ryuna | 3:cd7d3613e8e4 | 185 | //Way |
ryuna | 1:807091115672 | 186 | |
ryuna | 6:6664c6aa67d3 | 187 | /*if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 188 | if(!MotorState[1]){ |
ryuna | 3:cd7d3613e8e4 | 189 | |
ryuna | 3:cd7d3613e8e4 | 190 | StopTimer[2].attach(&MotorStop2,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 191 | Motor = Motor | 0x08; |
ryuna | 3:cd7d3613e8e4 | 192 | MotorState[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 193 | Led[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 194 | }else{ |
ryuna | 3:cd7d3613e8e4 | 195 | Flag[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 196 | } |
ryuna | 6:6664c6aa67d3 | 197 | }else */ |
ryuna | 6:6664c6aa67d3 | 198 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 199 | |
ryuna | 3:cd7d3613e8e4 | 200 | if(Flag[1]&&!FlagAdd[1]){ |
ryuna | 3:cd7d3613e8e4 | 201 | FlagAdd[1] = 1; |
ryuna | 5:aba9f5e97e03 | 202 | }else if(MotorState[1]){ |
ryuna | 3:cd7d3613e8e4 | 203 | StopTimer[3].attach(&MotorStop3,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 204 | Motor = Motor | 0x04; |
ryuna | 3:cd7d3613e8e4 | 205 | MotorState[1] = 0; |
ryuna | 3:cd7d3613e8e4 | 206 | Flag[1] = 0; |
ryuna | 6:6664c6aa67d3 | 207 | FlagAdd[1] = 0; |
ryuna | 3:cd7d3613e8e4 | 208 | Led[1] = 0; |
ryuna | 3:cd7d3613e8e4 | 209 | And[1] = 1; |
ryuna | 3:cd7d3613e8e4 | 210 | |
ryuna | 3:cd7d3613e8e4 | 211 | } |
ryuna | 3:cd7d3613e8e4 | 212 | } |
ryuna | 3:cd7d3613e8e4 | 213 | } |
ryuna | 3:cd7d3613e8e4 | 214 | void FallPhoto4(){//four |
ryuna | 3:cd7d3613e8e4 | 215 | |
ryuna | 3:cd7d3613e8e4 | 216 | if(Way ==0){ |
ryuna | 3:cd7d3613e8e4 | 217 | Way = 1; |
ryuna | 3:cd7d3613e8e4 | 218 | } |
ryuna | 3:cd7d3613e8e4 | 219 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 220 | if(!MotorState[2]){ |
ryuna | 3:cd7d3613e8e4 | 221 | StopTimer[4].attach(&MotorStop4,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 222 | Motor = Motor | 0x20;//00100000 |
ryuna | 3:cd7d3613e8e4 | 223 | MotorState[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 224 | Led[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 225 | }else{ |
ryuna | 3:cd7d3613e8e4 | 226 | Flag[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 227 | } |
ryuna | 6:6664c6aa67d3 | 228 | }/*else if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 229 | |
ryuna | 3:cd7d3613e8e4 | 230 | if(Flag[2]&&!FlagAdd[2]){ |
ryuna | 3:cd7d3613e8e4 | 231 | FlagAdd[2] = 1; |
ryuna | 5:aba9f5e97e03 | 232 | }else if(MotorState[2]){ |
ryuna | 3:cd7d3613e8e4 | 233 | StopTimer[5].attach(&MotorStop5,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 234 | Motor = Motor | 0x10; |
ryuna | 3:cd7d3613e8e4 | 235 | MotorState[2] = 0; |
ryuna | 3:cd7d3613e8e4 | 236 | Flag[2] = 0; |
ryuna | 3:cd7d3613e8e4 | 237 | Led[2] = 0; |
ryuna | 3:cd7d3613e8e4 | 238 | And[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 239 | |
ryuna | 3:cd7d3613e8e4 | 240 | } |
ryuna | 6:6664c6aa67d3 | 241 | } */ |
ryuna | 3:cd7d3613e8e4 | 242 | |
ryuna | 3:cd7d3613e8e4 | 243 | } |
ryuna | 3:cd7d3613e8e4 | 244 | void FallPhoto5(){//five |
ryuna | 6:6664c6aa67d3 | 245 | /*if(Way ==0){ |
ryuna | 3:cd7d3613e8e4 | 246 | Way = 2; |
ryuna | 6:6664c6aa67d3 | 247 | }*/ |
ryuna | 3:cd7d3613e8e4 | 248 | |
ryuna | 6:6664c6aa67d3 | 249 | /*if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 250 | if(!MotorState[2]){ |
ryuna | 3:cd7d3613e8e4 | 251 | StopTimer[4].attach(&MotorStop4,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 252 | Motor = Motor | 0x20;//00100000 |
ryuna | 3:cd7d3613e8e4 | 253 | MotorState[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 254 | Led[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 255 | }else{ |
ryuna | 3:cd7d3613e8e4 | 256 | Flag[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 257 | } |
ryuna | 6:6664c6aa67d3 | 258 | }else */ |
ryuna | 6:6664c6aa67d3 | 259 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 260 | |
ryuna | 3:cd7d3613e8e4 | 261 | if(Flag[2]&&!FlagAdd[2]){ |
ryuna | 3:cd7d3613e8e4 | 262 | FlagAdd[2] = 1; |
ryuna | 5:aba9f5e97e03 | 263 | }else if(MotorState[2]){ |
ryuna | 3:cd7d3613e8e4 | 264 | StopTimer[5].attach(&MotorStop5,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 265 | Motor = Motor | 0x10; |
ryuna | 3:cd7d3613e8e4 | 266 | MotorState[2] = 0; |
ryuna | 3:cd7d3613e8e4 | 267 | Flag[2] = 0; |
ryuna | 6:6664c6aa67d3 | 268 | FlagAdd[2] = 0; |
ryuna | 3:cd7d3613e8e4 | 269 | Led[2] = 0; |
ryuna | 3:cd7d3613e8e4 | 270 | And[2] = 1; |
ryuna | 3:cd7d3613e8e4 | 271 | } |
ryuna | 3:cd7d3613e8e4 | 272 | } |
ryuna | 3:cd7d3613e8e4 | 273 | } |
ryuna | 3:cd7d3613e8e4 | 274 | void FallPhoto6(){//six |
ryuna | 3:cd7d3613e8e4 | 275 | |
ryuna | 3:cd7d3613e8e4 | 276 | |
ryuna | 3:cd7d3613e8e4 | 277 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 278 | if(!MotorState[3]){ |
ryuna | 3:cd7d3613e8e4 | 279 | StopTimer[6].attach(&MotorStop6,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 280 | Motor = Motor | 0x02; |
ryuna | 3:cd7d3613e8e4 | 281 | MotorState[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 282 | Led[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 283 | }else{ |
ryuna | 3:cd7d3613e8e4 | 284 | Flag[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 285 | } |
ryuna | 6:6664c6aa67d3 | 286 | }/*else if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 287 | |
ryuna | 3:cd7d3613e8e4 | 288 | if(Flag[3]&&!FlagAdd[3]){ |
ryuna | 3:cd7d3613e8e4 | 289 | FlagAdd[3] = 1; |
ryuna | 5:aba9f5e97e03 | 290 | }else if(MotorState[3]){ |
ryuna | 3:cd7d3613e8e4 | 291 | StopTimer[7].attach(&MotorStop7,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 292 | Motor = Motor | 0x01; |
ryuna | 3:cd7d3613e8e4 | 293 | MotorState[3] = 0; |
ryuna | 3:cd7d3613e8e4 | 294 | Flag[3] = 0; |
ryuna | 3:cd7d3613e8e4 | 295 | Led[3] = 0; |
ryuna | 3:cd7d3613e8e4 | 296 | And[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 297 | } |
ryuna | 6:6664c6aa67d3 | 298 | } */ |
ryuna | 3:cd7d3613e8e4 | 299 | } |
ryuna | 3:cd7d3613e8e4 | 300 | void FallPhoto7(){//seven |
ryuna | 3:cd7d3613e8e4 | 301 | |
ryuna | 3:cd7d3613e8e4 | 302 | |
ryuna | 3:cd7d3613e8e4 | 303 | |
ryuna | 6:6664c6aa67d3 | 304 | /*if(Way == 2){ |
ryuna | 3:cd7d3613e8e4 | 305 | if(!MotorState[3]){ |
ryuna | 3:cd7d3613e8e4 | 306 | StopTimer[6].attach(&MotorStop6,MOVE_TIME); |
ryuna | 3:cd7d3613e8e4 | 307 | Motor = Motor | 0x02; |
ryuna | 3:cd7d3613e8e4 | 308 | MotorState[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 309 | Led[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 310 | }else{ |
ryuna | 3:cd7d3613e8e4 | 311 | Flag[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 312 | } |
ryuna | 6:6664c6aa67d3 | 313 | }else */ |
ryuna | 6:6664c6aa67d3 | 314 | if(Way == 1){ |
ryuna | 3:cd7d3613e8e4 | 315 | |
ryuna | 3:cd7d3613e8e4 | 316 | if(Flag[3]&&!FlagAdd[3]){ |
ryuna | 3:cd7d3613e8e4 | 317 | FlagAdd[3] = 1; |
ryuna | 5:aba9f5e97e03 | 318 | }else if(MotorState[3]){ |
ryuna | 3:cd7d3613e8e4 | 319 | StopTimer[7].attach(&MotorStop7,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 320 | Motor = Motor | 0x01; |
ryuna | 3:cd7d3613e8e4 | 321 | MotorState[3] = 0; |
ryuna | 3:cd7d3613e8e4 | 322 | Flag[3] = 0; |
ryuna | 6:6664c6aa67d3 | 323 | FlagAdd[3] = 0; |
ryuna | 3:cd7d3613e8e4 | 324 | Led[3] = 0; |
ryuna | 3:cd7d3613e8e4 | 325 | And[3] = 1; |
ryuna | 3:cd7d3613e8e4 | 326 | } |
ryuna | 3:cd7d3613e8e4 | 327 | } |
ryuna | 3:cd7d3613e8e4 | 328 | } |
ryuna | 3:cd7d3613e8e4 | 329 | |
ryuna | 3:cd7d3613e8e4 | 330 | void Reset(){ |
ryuna | 3:cd7d3613e8e4 | 331 | |
ryuna | 3:cd7d3613e8e4 | 332 | int i; |
ryuna | 3:cd7d3613e8e4 | 333 | |
ryuna | 3:cd7d3613e8e4 | 334 | if(MotorState[0]){ |
ryuna | 3:cd7d3613e8e4 | 335 | StopTimer[1].attach(&MotorStop1,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 336 | Motor = Motor | 0x40;// |
ryuna | 3:cd7d3613e8e4 | 337 | } |
ryuna | 3:cd7d3613e8e4 | 338 | if(MotorState[1]){ |
ryuna | 3:cd7d3613e8e4 | 339 | StopTimer[3].attach(&MotorStop3,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 340 | Motor = Motor | 0x04;//00000100 |
ryuna | 3:cd7d3613e8e4 | 341 | } |
ryuna | 3:cd7d3613e8e4 | 342 | if(MotorState[2]){ |
ryuna | 3:cd7d3613e8e4 | 343 | StopTimer[5].attach(&MotorStop5,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 344 | Motor = Motor | 0x10;//00010000 |
ryuna | 3:cd7d3613e8e4 | 345 | } |
ryuna | 3:cd7d3613e8e4 | 346 | if(MotorState[3]){ |
ryuna | 3:cd7d3613e8e4 | 347 | StopTimer[7].attach(&MotorStop7,MOVE_DOWN_TIME); |
ryuna | 3:cd7d3613e8e4 | 348 | Motor = Motor | 0x01;//00000001 |
ryuna | 3:cd7d3613e8e4 | 349 | } |
ryuna | 3:cd7d3613e8e4 | 350 | for(i = 0; i > 4; i++){ |
ryuna | 4:04f2479b83c1 | 351 | Led[i] = 0; |
ryuna | 3:cd7d3613e8e4 | 352 | Flag[i] = 0; |
ryuna | 3:cd7d3613e8e4 | 353 | FlagAdd[i] = 0; |
ryuna | 3:cd7d3613e8e4 | 354 | MotorState[i] = 0; |
ryuna | 4:04f2479b83c1 | 355 | And[i] = 0; |
ryuna | 1:807091115672 | 356 | } |
ryuna | 4:04f2479b83c1 | 357 | Way = 0; |
ryuna | 4:04f2479b83c1 | 358 | UpCt = 0; |
ryuna | 1:807091115672 | 359 | |
ryuna | 1:807091115672 | 360 | } |
ryuna | 0:76ba33d3b4a6 | 361 | |
ryuna | 3:cd7d3613e8e4 | 362 | void NumCount(){//足を上げた回数を記録 |
ryuna | 6:6664c6aa67d3 | 363 | UpCt ++; |
ryuna | 6:6664c6aa67d3 | 364 | And[0] = 0 ; |
ryuna | 6:6664c6aa67d3 | 365 | And[1] = 0 ; |
ryuna | 6:6664c6aa67d3 | 366 | And[2] = 0 ; |
ryuna | 6:6664c6aa67d3 | 367 | And[3] = 0 ; |
ryuna | 6:6664c6aa67d3 | 368 | TempraFlag = 0; |
ryuna | 6:6664c6aa67d3 | 369 | if(UpCt > 3){ |
ryuna | 6:6664c6aa67d3 | 370 | UpCt = 0; |
ryuna | 6:6664c6aa67d3 | 371 | Way = 0; |
ryuna | 1:807091115672 | 372 | } |
ryuna | 1:807091115672 | 373 | } |
ryuna | 1:807091115672 | 374 | |
ryuna | 3:cd7d3613e8e4 | 375 | void SetUp(){ |
ryuna | 6:6664c6aa67d3 | 376 | //int i; |
ryuna | 5:aba9f5e97e03 | 377 | |
ryuna | 5:aba9f5e97e03 | 378 | Pwm[0] = PWM_LEVEL ; |
ryuna | 5:aba9f5e97e03 | 379 | Pwm[1] = PWM_LEVEL ; |
ryuna | 5:aba9f5e97e03 | 380 | Pwm[2] = PWM_LEVEL ; |
ryuna | 5:aba9f5e97e03 | 381 | Pwm[3] = PWM_LEVEL ; |
ryuna | 6:6664c6aa67d3 | 382 | //for(i = 0 ; i > MOTOR_NUM ; i++ ){ |
ryuna | 6:6664c6aa67d3 | 383 | Photo[0].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 384 | Photo[1].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 385 | Photo[2].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 386 | Photo[3].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 387 | Photo[4].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 388 | Photo[5].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 389 | Photo[6].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 390 | Photo[7].mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 391 | |
ryuna | 6:6664c6aa67d3 | 392 | //} |
ryuna | 3:cd7d3613e8e4 | 393 | Photo[0].fall(FallPhoto0); |
ryuna | 3:cd7d3613e8e4 | 394 | Photo[1].fall(FallPhoto1); |
ryuna | 3:cd7d3613e8e4 | 395 | Photo[2].fall(FallPhoto2); |
ryuna | 3:cd7d3613e8e4 | 396 | Photo[3].fall(FallPhoto3); |
ryuna | 3:cd7d3613e8e4 | 397 | Photo[4].fall(FallPhoto4); |
ryuna | 3:cd7d3613e8e4 | 398 | Photo[5].fall(FallPhoto5); |
ryuna | 3:cd7d3613e8e4 | 399 | Photo[6].fall(FallPhoto6); |
ryuna | 3:cd7d3613e8e4 | 400 | Photo[7].fall(FallPhoto7); |
ryuna | 1:807091115672 | 401 | |
ryuna | 6:6664c6aa67d3 | 402 | // Sw.mode(PullUp); |
ryuna | 6:6664c6aa67d3 | 403 | // Sw.fall(Reset); |
ryuna | 3:cd7d3613e8e4 | 404 | |
ryuna | 1:807091115672 | 405 | |
ryuna | 1:807091115672 | 406 | } |
ryuna | 1:807091115672 | 407 | |
ryuna | 0:76ba33d3b4a6 | 408 | int main() { |
ryuna | 2:89cf1003e119 | 409 | |
ryuna | 3:cd7d3613e8e4 | 410 | SetUp(); |
ryuna | 3:cd7d3613e8e4 | 411 | wait(0.5); |
ryuna | 2:89cf1003e119 | 412 | |
ryuna | 1:807091115672 | 413 | while(1){ |
ryuna | 6:6664c6aa67d3 | 414 | if(MotorState[0]||MotorState[1]||MotorState[2]||MotorState[3]){ |
ryuna | 6:6664c6aa67d3 | 415 | TempraFlag = 1; |
ryuna | 6:6664c6aa67d3 | 416 | Tempra = 0x0A; |
ryuna | 6:6664c6aa67d3 | 417 | }else if(TempraFlag){ |
ryuna | 6:6664c6aa67d3 | 418 | StopTempra.attach(&TempraStop,TEMPRA_TIME); |
ryuna | 6:6664c6aa67d3 | 419 | TempraFlag = 0; |
ryuna | 6:6664c6aa67d3 | 420 | } |
ryuna | 6:6664c6aa67d3 | 421 | |
ryuna | 6:6664c6aa67d3 | 422 | if(And[0]&&And[1]&&And[2]&&And[3]){ |
ryuna | 6:6664c6aa67d3 | 423 | NumCount(); |
ryuna | 6:6664c6aa67d3 | 424 | } |
ryuna | 6:6664c6aa67d3 | 425 | |
ryuna | 6:6664c6aa67d3 | 426 | //printf("%d\t%d\n",UpCt,Way); |
ryuna | 0:76ba33d3b4a6 | 427 | } |
ryuna | 0:76ba33d3b4a6 | 428 | } |