Hello guys! I am pretty new in the world of arduinos. I am currently doing a project where i use 2 BTS7960 to control four motors. My problem is after i set up if conditions to be able to control the movement of the robot with a remote control, the movement of the engines completely mess up. Even though testing the motors without the if conditions seemed to be working fine and had no problems with the behaviour of the motors. This is my code since i can't upload files. Thanks for your help in advance!
#include <IRremote.h>
int jobbr_pwm = 3;
int jobbl_pwm = 5;
int balr_pwm = 9;
int ball_pwm = 10;
//int sw = 2;
//int button;
//const int x = 0;
//const int y = 1;
IRrecv IR(11);
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
//pinMode(0, INPUT);
//pinMode(1, INPUT);
//pinMode(sw, INPUT);
//digitalWrite(sw, HIGH);
Serial.begin(9600);
IR.enableIRIn();
}
void loop() {
// put your main code here, to run repeatedly:
if(IR.decode()){
Serial.println("i am here");
Serial.println(IR.decodedIRData.decodedRawData, HEX);
if (IR.decodedIRData.decodedRawData == 0x65DC8646 ){ // elore
Serial.println("i go forward");
analogWrite(jobbr_pwm, 50);
analogWrite(jobbl_pwm, 0);
analogWrite(balr_pwm, 50);
analogWrite(ball_pwm, 0);
Serial.println("forward");
IR.resume();
} else if (IR.decodedIRData.decodedRawData == 0xCC112BC2){ // hatra
analogWrite(jobbr_pwm, 0);
analogWrite(jobbl_pwm, 50);
analogWrite(balr_pwm, 0);
analogWrite(ball_pwm, 50);
Serial.println("backwards");
IR.resume();
} else if (IR.decodedIRData.decodedRawData == 0x879B92C2){ // balra
analogWrite(jobbr_pwm, 0);
analogWrite(jobbl_pwm, 50);
analogWrite(balr_pwm, 50);
analogWrite(ball_pwm, 0);
Serial.println("left");
IR.resume();
} else if (IR.decodedIRData.decodedRawData == 0x46868606 ){ // jobbra
analogWrite(jobbr_pwm, 50);
analogWrite(jobbl_pwm, 0);
analogWrite(balr_pwm, 0);
analogWrite(ball_pwm, 50);
Serial.println("right");
delay(200);
IR.resume();
} else if (IR.decodedIRData.decodedRawData == 0x28DE45AA ){ // all
// If you intend to do something when this condition is met, add the corresponding code here.
analogWrite(jobbr_pwm, 0);
analogWrite(jobbl_pwm, 0);
analogWrite(balr_pwm, 0);
analogWrite(ball_pwm, 0);
IR.resume();
Serial.println("stop");
} else {
}
}
}