The decoder reads the first byte ('$') to check whether the message is valid. it then reads the second and third bytes as a directive (M, T, in this case) to invoke the motor test. The fourth byte is the motor speed in rev/sec (range of 1 - 9). The fifth byte is ignored and the sixth byte sets the motor direction.
Here's the code...
Code: Select all
else if((readbuff[1] == 'M')&&(readbuff[2] == 'T')){ //Motor test
//WRITE CODE test motors
//spd = readbuff[3];
switch (readbuff[3]){ // Speed select
case '1': DelayCnt = 500;
case '2': DelayCnt = 250;
case '3': DelayCnt = 167;
case '4': DelayCnt = 125;
case '5': DelayCnt = 100;
case '6': DelayCnt = 83;
case '8': DelayCnt = 63;
case '9': DelayCnt = 56;
default: DelayCnt = 500;
}
if(readbuff[5] == '1'){ // Motor direction
MD1 = 1;
}
else{
MD1 = 0;
}
for(gg = 0; gg < 5; gg++){ // Spin 5 turns
Turn();
}
}
I am monitoring the output array from the PC in a watch window and all the elements are correct. I have tried using hex and decimal comparison (i.e case 0x31: DelayCnt = 500; or case 49: DelayCnt = 500;) but the result is the same.
Any ideas why the Switch statement isn't working?