Hi, i am trying to turn 2 motors on and off using a IR remote control and the R-robotics 2A motor shield, i can turn 1 motor on and off or 2 at the same time but if i try to give each motor its own on off buttons only 1 motor works even though the serial monitor is saying the buttons been pressed.I must be missing something or got the code wrong i would be grateful of any help.
// IR 2 motor test
#include <IRremote.h> // use the library
int E1 = 6;
int M1 = 7;
int E2 = 5;
int M2 = 4;
int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results;
void setup()
{
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
Serial.begin(9600); // for serial monitor output
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
{
if (results.value == 0x687CBE2L) { // 0x687CBE2L button press on remote control
Serial.write("1st motor ON\n");
digitalWrite(M1,HIGH);
analogWrite(E1, 200); //PWM Speed Control
delay(100); // waits 1s for the motor to reach the speed
}
else if (results.value == 0x687CBEAL) { //Press off button on remote control
Serial.write("1st motor off\n");
analogWrite(E1, 0); //PWM Speed Control
delay(100); // waits 1s for the motor to reach the speed
if (results.value == 0x687CBD0) { // On button press on remote control
Serial.write("2nd motor ON\n");
digitalWrite(M2,HIGH);
analogWrite(E2, 200); //PWM Speed Control
delay(100); // waits 1s for the motor to reach the speed
}
else if (results.value == 0x687CBD6) { //Press off button on remote control
Serial.write("2nd motor off\n");
analogWrite(E2, 0); //PWM Speed Control
delay(100); // waits 1s for the motor to reach the speed
}
}
}
Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal
irrecv.resume(); // receive the next value
} // Your loop can do other things while waiting for an IR command
}