So basically I want to make a code like the subject says;
if (result_A) {
do something
}
if STILL (result_A) {
do another thing
}
My question is how should I go about this. I've written the code below and I want it to work like if code 1 isn't read, then turn machine left, if code 1 still isn't read turn the machine right. Once the code is found, move the motor straight.
void motor_find() {
if(results.value != Tx_1_code_1) {
digitalWrite (dir_1,LOW); // left wheel will spin counterclockwise to create a pivot point for turning
digitalWrite (dir_2,HIGH); // right wheel spins in clockwise direction
analogWrite (pwm_1, 100); // speed of left motor is 100 bits/second
analogWrite (pwm_2, 100); // speed of right motor is 100 bits/second
if (results.value != Tx_1_code_1) { // if STILL not code 1, do next thing
digitalWrite (dir_1,LOW); // left wheel will spin counterclockwise to create a pivot point for turning
digitalWrite (dir_2,HIGH); // right wheel spins in clockwise direction
analogWrite (pwm_1, 100); // speed of left motor is 100 bits/second
analogWrite (pwm_2, 100); // speed of right motor is 100 bits/second
}
}
}
void realign() {
if (results.value != Tx_1_code_1) {
motor_find();
}
}
/* This code is apart of a different loop but it's where I want the motor to realign and once the */
/* signal is found, then go straight */
else {
Serial.println("AGV NOT STRAIGHT");
Serial.print("RECEIVER ONE signal received: ");
Serial.println(results.value, HEX);
Serial.println("REALIGN THE MOTOR");
Serial.println("");
irrecv_1.blink13(true);
realign(); // should realign the machine to find Tx_1_code_1
delay(500);
if (results.value == Tx_1_code_1) { // once code 1 found, go straight
motor_straight();
}
}
I'm not that experienced in Arduino, so if you could explain it fully I'd really appreciate it. Thank!