Why would digitalWrite cause IRremote to stop responding?
I'm using and arduino mega with a 2A motor controller from DFrobot on top.
Here's my code with the problematic sections commented out.
// Code for IRremote
#include <IRremote.h>
int receiver = 4;
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results decodedSignal;
///
// Motor code
//Arduino PWM Speed Control?
int E1 = 6;
int M1 = 7;
int E2 = 5;
int M2 = 4;
///
void setup()
{
Serial.begin(9600);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
int value=255;
if (irrecv.decode(&decodedSignal)) // have we received an IR signal?
{
if (decodedSignal.value == 0xFF4AB5) { // 8 backwards
Serial.println("backwards");
/* digitalWrite(M1,LOW);
digitalWrite(M2, LOW);
analogWrite(E1, value); //PWM Speed Control
analogWrite(E2, value); //PWM Speed Control
*/
}
else if (decodedSignal.value == 0xFF18E7) { //2 forward
Serial.println("forwards");
/* digitalWrite(M1,HIGH);
digitalWrite(M2, HIGH);
analogWrite(E1, value); //PWM Speed Control
analogWrite(E2, value); //PWM Speed Control
*/
}
else if (decodedSignal.value == 0xFF38C7) { //5 stop
Serial.println("stop");
}
else if (decodedSignal.value == 0xFF10EF) { //4 left
Serial.println("left");
/* digitalWrite(M1,LOW);
digitalWrite(M2, HIGH);
analogWrite(E1, value); //PWM Speed Control
analogWrite(E2, value); //PWM Speed Control
*/
}
else if (decodedSignal.value == 0xFF5AA5) { //6 right
Serial.println("right");
/* digitalWrite(M1,HIGH);
digitalWrite(M2, LOW);
analogWrite(E1, value); //PWM Speed Control
analogWrite(E2, value); //PWM Speed Control
*/
}
Serial.println(decodedSignal.value, HEX);
irrecv.resume(); // Receive the next value
}
}