void loop() {
float d = 0.3;
float s = 0.42;
while (IrReceiver.decode() == 0) {}
if (IrReceiver.decodedIRData.command == 0x46) {
Serial.println("forward");
car.forward(d, s);
}
if (IrReceiver.decodedIRData.command == 0x15) {
Serial.println("backward");
car.backward(0.3, 0.42);
}
if (IrReceiver.decodedIRData.command == 0x43) {
Serial.println("right");
car.right(90);
}
if (IrReceiver.decodedIRData.command == 0x44) {
Serial.println("left");
car.left(90);
}
IrReceiver.resume();
}
So this code reads from the IR, hangs in a loop if nothing is received and then does the moves based on the command code?
If so it might be better to use a switch case here...
Something along the lines of:
void loop() {
float d = 0.3;
float s = 0.42;
if (IrReceiver.decode() != 0) {
switch (IrReceiver.decodedIRData.command) {
case 0x46:
Serial.println("forward");
car.forward(d, s);
break;
case 0x15:
Serial.println("backward");
car.backward(0.3, 0.42);
break;
case 0x43:
Serial.println("right");
car.right(90);
break;
case 0x44:
Serial.println("left");
car.left(90);
break;
default:
break;
}
IrReceiver.resume();
}
}