I'm new to Arduino, and programming in general, and I am having an issue with a relitivly simple motor script, controlled via infa-red remote.
The issue that I am having, is once I press a button, it appears be constantly pressed (gathered this via the serial monitor), and pressing any other buttons have no effect, they do not show up on the serial monitor, nor do they change rotation of the motors.
As this is the first time I have used the switch command, I have a feeling this issue is a structure problem, but I am not certain.
#include <IRremote.h>
int REC = 8; //IR receiver pin (PWM)int ENA = 32;
int P1 = 30;
int P2 = 28;int ENB = 26;
int P01 = 24;
int P02 = 22;IRrecv irrecv(REC);
decode_results results; // results.value
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();pinMode(ENA, OUTPUT);
pinMode(P1, OUTPUT);
pinMode(P2, OUTPUT);pinMode(ENB, OUTPUT);
pinMode(P01, OUTPUT);
pinMode(P02, OUTPUT);}
void loop()
{
if (irrecv.decode(&results)){
Serial.println(results.value); //Print code along with button
switch(results.value){
case 0xFF18E7:Serial.println(" Forward");
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(P1, HIGH);
digitalWrite(P2, LOW);
digitalWrite(P01, HIGH);
digitalWrite(P02, LOW);
break;case 0xFF4AB5:
Serial.println(" Back");
digitalWrite(ENA, HIGH);
digitalWrite(ENB, HIGH);
digitalWrite(P1, LOW);
digitalWrite(P2, HIGH);
digitalWrite(P01, LOW);
digitalWrite(P02, HIGH);
break;}
delay(500);
}
}