When I'm running some test on my encoder motors using the following provided code by Makeblock, it appears that the if..else..
statement is not mutually exclusive ie. I can control Encoder_1 and Encoder_2 at the same time. How come?
case ENCODER_BOARD:
if(port == 0)
{
uint8_t slot = readBuffer(7);
int16_t speed_value = readShort(8);
speed_value = -speed_value;`
if(slot == SLOT_1)
{
Encoder_1.setTarPWM(speed_value);
}
else if(slot == SLOT_2)
{
Encoder_2.setTarPWM(speed_value);
}
else if(slot == SLOT_3)
{
Encoder_3.setTarPWM(speed_value);
}
else if(slot == SLOT_4)
{
Encoder_4.setTarPWM(speed_value);
}
}
int16_t readShort(int16_t idx)
{
valShort.byteVal[0] = readBuffer(idx);
valShort.byteVal[1] = readBuffer(idx+1);
return valShort.shortVal;
}
uint8_t readBuffer(int16_t index)
{
if(BluetoothSource == DATA_SERIAL)
{
return buffer[index];
}
else if(BluetoothSource == DATA_SERIAL2)
{
return bufferBt1[index];
}
else if(BluetoothSource == DATA_SERIAL3)
{
return bufferBt2[index];
}
}
All the code are taken from here and I am not the owner. I myself still studying how these whole code works. I am hoping someone out there who have experience with these kind of implementations be able to help me out.