Engine control program with 3 engines Needs to make a case for each simultaneous engine setting, because of the WAIT after each number of bits have been sent.

Dependencies:   mbed-rtos mbed PinDetect

Fork of FinalMotorControl by Robot Bachelor

Committer:
mjhaugsdal
Date:
Tue May 03 12:34:20 2016 +0000
Revision:
20:d90bd1718078
Parent:
19:79600d3509d7
Child:
21:9f3ae352ee63
Made each motor release before running.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rlanghbv 0:bd78e433db61 1 #include "mbed.h"
mjhaugsdal 1:a3287196a9b3 2 #include "rtos.h"
rlanghbv 0:bd78e433db61 3
rlanghbv 2:25bcc26f7a5b 4 Serial pc(USBTX, USBRX); // tx, rx
rlanghbv 0:bd78e433db61 5
mjhaugsdal 1:a3287196a9b3 6 //Analog Pins
mjhaugsdal 5:fdc7a779d525 7 //First engine
mjhaugsdal 5:fdc7a779d525 8 DigitalOut IN1(A0);
mjhaugsdal 5:fdc7a779d525 9 DigitalOut IN2(A1);
mjhaugsdal 5:fdc7a779d525 10 DigitalOut IN3(A2);
mjhaugsdal 5:fdc7a779d525 11 DigitalOut IN4(A3);
mjhaugsdal 5:fdc7a779d525 12 //Second engine
mjhaugsdal 6:ac5d277bd497 13 DigitalOut IN5(D3);
mjhaugsdal 6:ac5d277bd497 14 DigitalOut IN6(D4);
mjhaugsdal 6:ac5d277bd497 15 DigitalOut IN7(D5);
mjhaugsdal 6:ac5d277bd497 16 DigitalOut IN8(D6);
mjhaugsdal 16:a3555918c025 17 //Third Engine
mjhaugsdal 16:a3555918c025 18 DigitalOut IN9(D8);
mjhaugsdal 16:a3555918c025 19 DigitalOut IN10(D9);
mjhaugsdal 16:a3555918c025 20 DigitalOut IN11(D10);
mjhaugsdal 16:a3555918c025 21 DigitalOut IN12(D11);
mjhaugsdal 5:fdc7a779d525 22
rlanghbv 0:bd78e433db61 23
mjhaugsdal 1:a3287196a9b3 24 static int fart = 1000;
mjhaugsdal 3:15be78948724 25 static char m_cmd = 'x';
rlanghbv 0:bd78e433db61 26
rlanghbv 0:bd78e433db61 27
mjhaugsdal 5:fdc7a779d525 28
mjhaugsdal 17:ff0021c4dcdc 29 void stepAllRight()
rlanghbv 0:bd78e433db61 30 {
mjhaugsdal 6:ac5d277bd497 31 //engine 1
rlanghbv 0:bd78e433db61 32 IN1=0;
rlanghbv 0:bd78e433db61 33 IN2=1;
rlanghbv 0:bd78e433db61 34 IN3=0;
rlanghbv 0:bd78e433db61 35 IN4=1;
mjhaugsdal 6:ac5d277bd497 36 //engine 2
mjhaugsdal 6:ac5d277bd497 37 IN5=0;
mjhaugsdal 6:ac5d277bd497 38 IN6=1;
mjhaugsdal 6:ac5d277bd497 39 IN7=0;
mjhaugsdal 6:ac5d277bd497 40 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 41 //engine 3
mjhaugsdal 17:ff0021c4dcdc 42 IN9=0;
mjhaugsdal 17:ff0021c4dcdc 43 IN10=1;
mjhaugsdal 17:ff0021c4dcdc 44 IN11=0;
mjhaugsdal 17:ff0021c4dcdc 45 IN12=1;
mjhaugsdal 1:a3287196a9b3 46 wait_us(fart); //legg som global variabel "fart"
mjhaugsdal 6:ac5d277bd497 47 //engine 1
rlanghbv 0:bd78e433db61 48 IN1=0;
rlanghbv 0:bd78e433db61 49 IN2=1;
rlanghbv 0:bd78e433db61 50 IN3=1;
rlanghbv 0:bd78e433db61 51 IN4=0;
mjhaugsdal 6:ac5d277bd497 52 //engine 2
mjhaugsdal 6:ac5d277bd497 53 IN5=0;
mjhaugsdal 6:ac5d277bd497 54 IN6=1;
mjhaugsdal 6:ac5d277bd497 55 IN7=1;
mjhaugsdal 6:ac5d277bd497 56 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 57 //engine 3
mjhaugsdal 17:ff0021c4dcdc 58 IN9=0;
mjhaugsdal 17:ff0021c4dcdc 59 IN10=1;
mjhaugsdal 17:ff0021c4dcdc 60 IN11=1;
mjhaugsdal 17:ff0021c4dcdc 61 IN12=0;
mjhaugsdal 1:a3287196a9b3 62 wait_us(fart);
mjhaugsdal 6:ac5d277bd497 63 //engine 1
rlanghbv 0:bd78e433db61 64 IN1=1;
rlanghbv 0:bd78e433db61 65 IN2=0;
rlanghbv 0:bd78e433db61 66 IN3=1;
rlanghbv 0:bd78e433db61 67 IN4=0;
mjhaugsdal 6:ac5d277bd497 68 //engine 2
mjhaugsdal 6:ac5d277bd497 69 IN5=1;
mjhaugsdal 6:ac5d277bd497 70 IN6=0;
mjhaugsdal 6:ac5d277bd497 71 IN7=1;
mjhaugsdal 6:ac5d277bd497 72 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 73 //engine 3
mjhaugsdal 17:ff0021c4dcdc 74 IN9=1;
mjhaugsdal 17:ff0021c4dcdc 75 IN10=0;
mjhaugsdal 17:ff0021c4dcdc 76 IN11=1;
mjhaugsdal 17:ff0021c4dcdc 77 IN12=0;
mjhaugsdal 1:a3287196a9b3 78 wait_us(fart);
mjhaugsdal 6:ac5d277bd497 79 //engine 1
rlanghbv 0:bd78e433db61 80 IN1=1;
rlanghbv 0:bd78e433db61 81 IN2=0;
rlanghbv 0:bd78e433db61 82 IN3=0;
rlanghbv 0:bd78e433db61 83 IN4=1;
mjhaugsdal 6:ac5d277bd497 84 //engine 2
mjhaugsdal 6:ac5d277bd497 85 IN5=1;
mjhaugsdal 6:ac5d277bd497 86 IN6=0;
mjhaugsdal 6:ac5d277bd497 87 IN7=0;
mjhaugsdal 6:ac5d277bd497 88 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 89 //engine 3
mjhaugsdal 17:ff0021c4dcdc 90 IN9=1;
mjhaugsdal 17:ff0021c4dcdc 91 IN10=0;
mjhaugsdal 17:ff0021c4dcdc 92 IN11=0;
mjhaugsdal 17:ff0021c4dcdc 93 IN12=1;
mjhaugsdal 1:a3287196a9b3 94 wait_us(fart);
rlanghbv 0:bd78e433db61 95 }
mjhaugsdal 17:ff0021c4dcdc 96 void stepAllLeft()
rlanghbv 0:bd78e433db61 97 {
mjhaugsdal 6:ac5d277bd497 98 //engine 1
rlanghbv 0:bd78e433db61 99 IN1=1;
rlanghbv 0:bd78e433db61 100 IN2=0;
rlanghbv 0:bd78e433db61 101 IN3=0;
rlanghbv 0:bd78e433db61 102 IN4=1;
mjhaugsdal 6:ac5d277bd497 103 //engine 2
mjhaugsdal 6:ac5d277bd497 104 IN5=1;
mjhaugsdal 6:ac5d277bd497 105 IN6=0;
mjhaugsdal 6:ac5d277bd497 106 IN7=0;
mjhaugsdal 6:ac5d277bd497 107 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 108 //engine 3
mjhaugsdal 17:ff0021c4dcdc 109 IN9=1;
mjhaugsdal 17:ff0021c4dcdc 110 IN10=0;
mjhaugsdal 17:ff0021c4dcdc 111 IN11=0;
mjhaugsdal 17:ff0021c4dcdc 112 IN12=1;
mjhaugsdal 1:a3287196a9b3 113 wait_us(fart);
mjhaugsdal 6:ac5d277bd497 114 //engine 1
rlanghbv 0:bd78e433db61 115 IN1=1;
rlanghbv 0:bd78e433db61 116 IN2=0;
rlanghbv 0:bd78e433db61 117 IN3=1;
rlanghbv 0:bd78e433db61 118 IN4=0;
mjhaugsdal 6:ac5d277bd497 119 //engine 2
mjhaugsdal 6:ac5d277bd497 120 IN5=1;
mjhaugsdal 6:ac5d277bd497 121 IN6=0;
mjhaugsdal 6:ac5d277bd497 122 IN7=1;
mjhaugsdal 6:ac5d277bd497 123 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 124 //engine 3
mjhaugsdal 17:ff0021c4dcdc 125 IN9=1;
mjhaugsdal 17:ff0021c4dcdc 126 IN10=0;
mjhaugsdal 17:ff0021c4dcdc 127 IN11=1;
mjhaugsdal 17:ff0021c4dcdc 128 IN12=0;
mjhaugsdal 1:a3287196a9b3 129 wait_us(fart);
mjhaugsdal 6:ac5d277bd497 130 //engine 1
rlanghbv 0:bd78e433db61 131 IN1=0;
rlanghbv 0:bd78e433db61 132 IN2=1;
rlanghbv 0:bd78e433db61 133 IN3=1;
rlanghbv 0:bd78e433db61 134 IN4=0;
mjhaugsdal 6:ac5d277bd497 135 //engine 2
mjhaugsdal 6:ac5d277bd497 136 IN5=0;
mjhaugsdal 6:ac5d277bd497 137 IN6=1;
mjhaugsdal 6:ac5d277bd497 138 IN7=1;
mjhaugsdal 6:ac5d277bd497 139 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 140 //engine 3
mjhaugsdal 17:ff0021c4dcdc 141 IN9=0;
mjhaugsdal 17:ff0021c4dcdc 142 IN10=1;
mjhaugsdal 17:ff0021c4dcdc 143 IN11=1;
mjhaugsdal 17:ff0021c4dcdc 144 IN12=0;
mjhaugsdal 1:a3287196a9b3 145 wait_us(fart);
mjhaugsdal 6:ac5d277bd497 146 //engine 1
rlanghbv 0:bd78e433db61 147 IN1=0;
rlanghbv 0:bd78e433db61 148 IN2=1;
rlanghbv 0:bd78e433db61 149 IN3=0;
rlanghbv 0:bd78e433db61 150 IN4=1;
mjhaugsdal 6:ac5d277bd497 151 //engine 2
mjhaugsdal 6:ac5d277bd497 152 IN5=0;
mjhaugsdal 6:ac5d277bd497 153 IN6=1;
mjhaugsdal 6:ac5d277bd497 154 IN7=0;
mjhaugsdal 6:ac5d277bd497 155 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 156 //engine 3
mjhaugsdal 17:ff0021c4dcdc 157 IN9=0;
mjhaugsdal 17:ff0021c4dcdc 158 IN10=1;
mjhaugsdal 17:ff0021c4dcdc 159 IN11=0;
mjhaugsdal 17:ff0021c4dcdc 160 IN12=1;
mjhaugsdal 17:ff0021c4dcdc 161 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 162 }
mjhaugsdal 17:ff0021c4dcdc 163
mjhaugsdal 17:ff0021c4dcdc 164 void stepEngine1Left()
mjhaugsdal 17:ff0021c4dcdc 165 {
mjhaugsdal 17:ff0021c4dcdc 166 //engine 1
mjhaugsdal 17:ff0021c4dcdc 167 IN1=1;
mjhaugsdal 17:ff0021c4dcdc 168 IN2=0;
mjhaugsdal 17:ff0021c4dcdc 169 IN3=0;
mjhaugsdal 17:ff0021c4dcdc 170 IN4=1;
mjhaugsdal 17:ff0021c4dcdc 171 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 172 IN1=1;
mjhaugsdal 17:ff0021c4dcdc 173 IN2=0;
mjhaugsdal 17:ff0021c4dcdc 174 IN3=1;
mjhaugsdal 17:ff0021c4dcdc 175 IN4=0;
mjhaugsdal 17:ff0021c4dcdc 176 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 177 IN1=0;
mjhaugsdal 17:ff0021c4dcdc 178 IN2=1;
mjhaugsdal 17:ff0021c4dcdc 179 IN3=1;
mjhaugsdal 17:ff0021c4dcdc 180 IN4=0;
mjhaugsdal 17:ff0021c4dcdc 181 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 182 IN1=0;
mjhaugsdal 17:ff0021c4dcdc 183 IN2=1;
mjhaugsdal 17:ff0021c4dcdc 184 IN3=0;
mjhaugsdal 17:ff0021c4dcdc 185 IN4=1;
mjhaugsdal 1:a3287196a9b3 186 wait_us(fart);
rlanghbv 0:bd78e433db61 187 }
rlanghbv 0:bd78e433db61 188
mjhaugsdal 17:ff0021c4dcdc 189 void stepEngine1Right()
mjhaugsdal 17:ff0021c4dcdc 190 {
mjhaugsdal 17:ff0021c4dcdc 191 //engine 1
mjhaugsdal 17:ff0021c4dcdc 192 IN1=0;
mjhaugsdal 17:ff0021c4dcdc 193 IN2=1;
mjhaugsdal 17:ff0021c4dcdc 194 IN3=0;
mjhaugsdal 17:ff0021c4dcdc 195 IN4=1;
mjhaugsdal 17:ff0021c4dcdc 196 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 197 IN1=0;
mjhaugsdal 17:ff0021c4dcdc 198 IN2=1;
mjhaugsdal 17:ff0021c4dcdc 199 IN3=1;
mjhaugsdal 17:ff0021c4dcdc 200 IN4=0;
mjhaugsdal 17:ff0021c4dcdc 201 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 202 IN1=1;
mjhaugsdal 17:ff0021c4dcdc 203 IN2=0;
mjhaugsdal 17:ff0021c4dcdc 204 IN3=1;
mjhaugsdal 17:ff0021c4dcdc 205 IN4=0;
mjhaugsdal 17:ff0021c4dcdc 206 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 207 IN1=1;
mjhaugsdal 17:ff0021c4dcdc 208 IN2=0;
mjhaugsdal 17:ff0021c4dcdc 209 IN3=0;
mjhaugsdal 17:ff0021c4dcdc 210 IN4=1;
mjhaugsdal 17:ff0021c4dcdc 211 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 212 }
mjhaugsdal 17:ff0021c4dcdc 213
mjhaugsdal 17:ff0021c4dcdc 214 void stepEngine2Right()
mjhaugsdal 17:ff0021c4dcdc 215 {
mjhaugsdal 17:ff0021c4dcdc 216 //engine 1
mjhaugsdal 17:ff0021c4dcdc 217 IN5=0;
mjhaugsdal 17:ff0021c4dcdc 218 IN6=1;
mjhaugsdal 17:ff0021c4dcdc 219 IN7=0;
mjhaugsdal 17:ff0021c4dcdc 220 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 221 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 222 IN5=0;
mjhaugsdal 17:ff0021c4dcdc 223 IN6=1;
mjhaugsdal 17:ff0021c4dcdc 224 IN7=1;
mjhaugsdal 17:ff0021c4dcdc 225 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 226 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 227 IN5=1;
mjhaugsdal 17:ff0021c4dcdc 228 IN6=0;
mjhaugsdal 17:ff0021c4dcdc 229 IN7=1;
mjhaugsdal 17:ff0021c4dcdc 230 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 231 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 232 IN5=1;
mjhaugsdal 17:ff0021c4dcdc 233 IN6=0;
mjhaugsdal 17:ff0021c4dcdc 234 IN7=0;
mjhaugsdal 17:ff0021c4dcdc 235 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 236 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 237 }
mjhaugsdal 17:ff0021c4dcdc 238
mjhaugsdal 17:ff0021c4dcdc 239 void stepEngine2Left()
mjhaugsdal 17:ff0021c4dcdc 240 {
mjhaugsdal 17:ff0021c4dcdc 241 //engine 1
mjhaugsdal 17:ff0021c4dcdc 242 IN5=1;
mjhaugsdal 17:ff0021c4dcdc 243 IN6=0;
mjhaugsdal 17:ff0021c4dcdc 244 IN7=0;
mjhaugsdal 17:ff0021c4dcdc 245 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 246 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 247 IN5=1;
mjhaugsdal 17:ff0021c4dcdc 248 IN6=0;
mjhaugsdal 17:ff0021c4dcdc 249 IN7=1;
mjhaugsdal 17:ff0021c4dcdc 250 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 251 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 252 IN5=0;
mjhaugsdal 17:ff0021c4dcdc 253 IN6=1;
mjhaugsdal 17:ff0021c4dcdc 254 IN7=1;
mjhaugsdal 17:ff0021c4dcdc 255 IN8=0;
mjhaugsdal 17:ff0021c4dcdc 256 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 257 IN5=0;
mjhaugsdal 17:ff0021c4dcdc 258 IN6=1;
mjhaugsdal 17:ff0021c4dcdc 259 IN7=0;
mjhaugsdal 17:ff0021c4dcdc 260 IN8=1;
mjhaugsdal 17:ff0021c4dcdc 261 wait_us(fart);
mjhaugsdal 17:ff0021c4dcdc 262 }
mjhaugsdal 17:ff0021c4dcdc 263
mjhaugsdal 19:79600d3509d7 264 void stepEngine3Right()
mjhaugsdal 19:79600d3509d7 265 {
mjhaugsdal 19:79600d3509d7 266 //engine 1
mjhaugsdal 19:79600d3509d7 267 IN9=0;
mjhaugsdal 19:79600d3509d7 268 IN10=1;
mjhaugsdal 19:79600d3509d7 269 IN11=0;
mjhaugsdal 19:79600d3509d7 270 IN12=1;
mjhaugsdal 19:79600d3509d7 271 wait_us(fart);
mjhaugsdal 19:79600d3509d7 272 IN9=0;
mjhaugsdal 19:79600d3509d7 273 IN10=1;
mjhaugsdal 19:79600d3509d7 274 IN11=1;
mjhaugsdal 19:79600d3509d7 275 IN12=0;
mjhaugsdal 19:79600d3509d7 276 wait_us(fart);
mjhaugsdal 19:79600d3509d7 277 IN9=1;
mjhaugsdal 19:79600d3509d7 278 IN10=0;
mjhaugsdal 19:79600d3509d7 279 IN11=1;
mjhaugsdal 19:79600d3509d7 280 IN12=0;
mjhaugsdal 19:79600d3509d7 281 wait_us(fart);
mjhaugsdal 19:79600d3509d7 282 IN9=1;
mjhaugsdal 19:79600d3509d7 283 IN10=0;
mjhaugsdal 19:79600d3509d7 284 IN11=0;
mjhaugsdal 19:79600d3509d7 285 IN12=1;
mjhaugsdal 19:79600d3509d7 286 wait_us(fart);
mjhaugsdal 19:79600d3509d7 287 }
mjhaugsdal 19:79600d3509d7 288
mjhaugsdal 19:79600d3509d7 289 void stepEngine3Left()
mjhaugsdal 19:79600d3509d7 290 {
mjhaugsdal 19:79600d3509d7 291 //engine 1
mjhaugsdal 19:79600d3509d7 292 IN9=1;
mjhaugsdal 19:79600d3509d7 293 IN10=0;
mjhaugsdal 19:79600d3509d7 294 IN11=0;
mjhaugsdal 19:79600d3509d7 295 IN12=1;
mjhaugsdal 19:79600d3509d7 296 wait_us(fart);
mjhaugsdal 19:79600d3509d7 297 IN9=1;
mjhaugsdal 19:79600d3509d7 298 IN10=0;
mjhaugsdal 19:79600d3509d7 299 IN11=1;
mjhaugsdal 19:79600d3509d7 300 IN12=0;
mjhaugsdal 19:79600d3509d7 301 wait_us(fart);
mjhaugsdal 19:79600d3509d7 302 IN9=0;
mjhaugsdal 19:79600d3509d7 303 IN10=1;
mjhaugsdal 19:79600d3509d7 304 IN11=1;
mjhaugsdal 19:79600d3509d7 305 IN12=0;
mjhaugsdal 19:79600d3509d7 306 wait_us(fart);
mjhaugsdal 19:79600d3509d7 307 IN9=0;
mjhaugsdal 19:79600d3509d7 308 IN10=1;
mjhaugsdal 19:79600d3509d7 309 IN11=0;
mjhaugsdal 19:79600d3509d7 310 IN12=1;
mjhaugsdal 19:79600d3509d7 311 wait_us(fart);
mjhaugsdal 19:79600d3509d7 312 }
mjhaugsdal 19:79600d3509d7 313
mjhaugsdal 18:ef02a9014491 314 void stopAll()
mjhaugsdal 18:ef02a9014491 315 {
mjhaugsdal 18:ef02a9014491 316 IN1=0;
mjhaugsdal 18:ef02a9014491 317 IN2=0;
mjhaugsdal 18:ef02a9014491 318 IN3=0;
mjhaugsdal 18:ef02a9014491 319 IN4=0;
mjhaugsdal 18:ef02a9014491 320 IN5=0;
mjhaugsdal 18:ef02a9014491 321 IN6=0;
mjhaugsdal 18:ef02a9014491 322 IN7=0;
mjhaugsdal 18:ef02a9014491 323 IN8=0;
mjhaugsdal 18:ef02a9014491 324 IN9=0;
mjhaugsdal 18:ef02a9014491 325 IN10=0;
mjhaugsdal 18:ef02a9014491 326 IN11=0;
mjhaugsdal 18:ef02a9014491 327 IN12=0;
mjhaugsdal 18:ef02a9014491 328 }
mjhaugsdal 18:ef02a9014491 329
mjhaugsdal 20:d90bd1718078 330 void stopE1()
mjhaugsdal 20:d90bd1718078 331 {
mjhaugsdal 20:d90bd1718078 332 IN1=0;
mjhaugsdal 20:d90bd1718078 333 IN2=0;
mjhaugsdal 20:d90bd1718078 334 IN3=0;
mjhaugsdal 20:d90bd1718078 335 IN4=0;
mjhaugsdal 20:d90bd1718078 336
mjhaugsdal 20:d90bd1718078 337 }
mjhaugsdal 20:d90bd1718078 338 void stopE2()
mjhaugsdal 20:d90bd1718078 339 {
mjhaugsdal 20:d90bd1718078 340 IN5=0;
mjhaugsdal 20:d90bd1718078 341 IN6=0;
mjhaugsdal 20:d90bd1718078 342 IN7=0;
mjhaugsdal 20:d90bd1718078 343 IN8=0;
mjhaugsdal 20:d90bd1718078 344
mjhaugsdal 20:d90bd1718078 345 }
mjhaugsdal 20:d90bd1718078 346 void stopE3()
mjhaugsdal 20:d90bd1718078 347 {
mjhaugsdal 20:d90bd1718078 348 IN9=0;
mjhaugsdal 20:d90bd1718078 349 IN10=0;
mjhaugsdal 20:d90bd1718078 350 IN11=0;
mjhaugsdal 20:d90bd1718078 351 IN12=0;
mjhaugsdal 20:d90bd1718078 352
mjhaugsdal 20:d90bd1718078 353 }
mjhaugsdal 20:d90bd1718078 354
mjhaugsdal 17:ff0021c4dcdc 355
mjhaugsdal 17:ff0021c4dcdc 356
mjhaugsdal 19:79600d3509d7 357
mjhaugsdal 19:79600d3509d7 358
mjhaugsdal 1:a3287196a9b3 359 void input(void const *args)
mjhaugsdal 1:a3287196a9b3 360 {
mjhaugsdal 1:a3287196a9b3 361 while(true)
mjhaugsdal 1:a3287196a9b3 362 {
mjhaugsdal 3:15be78948724 363
rlanghbv 2:25bcc26f7a5b 364 if(pc.readable())
mjhaugsdal 3:15be78948724 365 { m_cmd=pc.getc();
mjhaugsdal 3:15be78948724 366
mjhaugsdal 17:ff0021c4dcdc 367 }
mjhaugsdal 17:ff0021c4dcdc 368
rlanghbv 2:25bcc26f7a5b 369 Thread::wait(10);
mjhaugsdal 5:fdc7a779d525 370 //pc.printf("%d", steps);
mjhaugsdal 1:a3287196a9b3 371 }
mjhaugsdal 1:a3287196a9b3 372 }
rlanghbv 0:bd78e433db61 373
rlanghbv 0:bd78e433db61 374 int main()
rlanghbv 0:bd78e433db61 375 {
mjhaugsdal 1:a3287196a9b3 376 //Thread 1 has constant feed from usb
rlanghbv 2:25bcc26f7a5b 377 Thread t1(input);
mjhaugsdal 3:15be78948724 378 static char global_direction;
mjhaugsdal 3:15be78948724 379 printf("Started");
mjhaugsdal 3:15be78948724 380
mjhaugsdal 5:fdc7a779d525 381
mjhaugsdal 1:a3287196a9b3 382 while (true)
mjhaugsdal 1:a3287196a9b3 383 {
mjhaugsdal 4:4d655fdae399 384 //Thread::wait(5);
mjhaugsdal 3:15be78948724 385
mjhaugsdal 19:79600d3509d7 386 /*
mjhaugsdal 19:79600d3509d7 387
mjhaugsdal 19:79600d3509d7 388
mjhaugsdal 4:4d655fdae399 389
mjhaugsdal 19:79600d3509d7 390
mjhaugsdal 5:fdc7a779d525 391 else if (m_cmd == 'k')
mjhaugsdal 1:a3287196a9b3 392 {
mjhaugsdal 6:ac5d277bd497 393 int steps = 242;
mjhaugsdal 5:fdc7a779d525 394
mjhaugsdal 5:fdc7a779d525 395
mjhaugsdal 6:ac5d277bd497 396 //Steps = 242 gives a 60' rotation to the left.
mjhaugsdal 5:fdc7a779d525 397 while (steps >= 0)
mjhaugsdal 5:fdc7a779d525 398 {
mjhaugsdal 17:ff0021c4dcdc 399 stepAllLeft();
mjhaugsdal 5:fdc7a779d525 400 steps--;
mjhaugsdal 5:fdc7a779d525 401 }
mjhaugsdal 5:fdc7a779d525 402 m_cmd = 'x';
mjhaugsdal 3:15be78948724 403 }
mjhaugsdal 5:fdc7a779d525 404 else if (m_cmd == 'l')
mjhaugsdal 5:fdc7a779d525 405 {
mjhaugsdal 6:ac5d277bd497 406 int steps = 242;
mjhaugsdal 6:ac5d277bd497 407 //Steps = 242 gives a 60' rotation to the right.
mjhaugsdal 5:fdc7a779d525 408 while (steps >= 0)
mjhaugsdal 5:fdc7a779d525 409 {
mjhaugsdal 17:ff0021c4dcdc 410 stepAllRight();
mjhaugsdal 5:fdc7a779d525 411 steps--;
mjhaugsdal 5:fdc7a779d525 412 }
mjhaugsdal 5:fdc7a779d525 413 m_cmd = 'x';
mjhaugsdal 5:fdc7a779d525 414
mjhaugsdal 19:79600d3509d7 415 }*/
mjhaugsdal 18:ef02a9014491 416 if (m_cmd == 'z')
mjhaugsdal 18:ef02a9014491 417 {
mjhaugsdal 18:ef02a9014491 418 stopAll();
mjhaugsdal 19:79600d3509d7 419 }
mjhaugsdal 19:79600d3509d7 420
mjhaugsdal 19:79600d3509d7 421 if (m_cmd == 'x')
mjhaugsdal 19:79600d3509d7 422 {
mjhaugsdal 19:79600d3509d7 423 Thread::wait(5);
mjhaugsdal 18:ef02a9014491 424 }
mjhaugsdal 19:79600d3509d7 425
mjhaugsdal 19:79600d3509d7 426 //ENGINE 1
mjhaugsdal 19:79600d3509d7 427 if(m_cmd == '7')
mjhaugsdal 19:79600d3509d7 428 {
mjhaugsdal 19:79600d3509d7 429 //fart = 1200;
mjhaugsdal 20:d90bd1718078 430 stopE1();
mjhaugsdal 19:79600d3509d7 431 stepEngine1Left();
mjhaugsdal 19:79600d3509d7 432 }
mjhaugsdal 19:79600d3509d7 433 else if (m_cmd == '9')
mjhaugsdal 19:79600d3509d7 434 {
mjhaugsdal 19:79600d3509d7 435 //fart = 1200;
mjhaugsdal 20:d90bd1718078 436 stopE1();
mjhaugsdal 19:79600d3509d7 437 stepEngine1Right();
mjhaugsdal 19:79600d3509d7 438 }
mjhaugsdal 19:79600d3509d7 439 //ENGINE 2
mjhaugsdal 19:79600d3509d7 440 else if (m_cmd == '4')
mjhaugsdal 19:79600d3509d7 441 {
mjhaugsdal 19:79600d3509d7 442 //fart = 1200;
mjhaugsdal 20:d90bd1718078 443 stopE2();
mjhaugsdal 19:79600d3509d7 444 stepEngine2Left();
mjhaugsdal 19:79600d3509d7 445 }
mjhaugsdal 19:79600d3509d7 446 else if (m_cmd == '6')
mjhaugsdal 19:79600d3509d7 447 {
mjhaugsdal 19:79600d3509d7 448 //fart = 1200;
mjhaugsdal 20:d90bd1718078 449 stopE2();
mjhaugsdal 19:79600d3509d7 450 stepEngine2Right();
mjhaugsdal 19:79600d3509d7 451 }
mjhaugsdal 19:79600d3509d7 452 //ENGINE 3
mjhaugsdal 19:79600d3509d7 453 else if (m_cmd == '1')
mjhaugsdal 19:79600d3509d7 454 {
mjhaugsdal 19:79600d3509d7 455 //fart = 1200;
mjhaugsdal 20:d90bd1718078 456 stopE3();
mjhaugsdal 19:79600d3509d7 457 stepEngine3Left();
mjhaugsdal 19:79600d3509d7 458 }
mjhaugsdal 19:79600d3509d7 459 else if (m_cmd == '3')
mjhaugsdal 19:79600d3509d7 460 {
mjhaugsdal 19:79600d3509d7 461 //fart = 1200;
mjhaugsdal 20:d90bd1718078 462 stopE3();
mjhaugsdal 19:79600d3509d7 463 stepEngine3Right();
mjhaugsdal 19:79600d3509d7 464 }
mjhaugsdal 5:fdc7a779d525 465
mjhaugsdal 5:fdc7a779d525 466
mjhaugsdal 4:4d655fdae399 467
mjhaugsdal 1:a3287196a9b3 468 }
mjhaugsdal 1:a3287196a9b3 469
mjhaugsdal 3:15be78948724 470 } //END Main