Hello all, I am new here and sorry in advance if I didn't post my code correctly.
I am creating a robot car using the arduino uno, in which I use an IR remote to either change the car to manual mode, meaning I can use the remote to control if the car goes forward, left, right, etc., or in automatic mode, which will use an ultrasonic sensor to navigate the area.
The problem I find myself in is once the manual mode button is pressed, I want it to go forward, left, right, etc. depending on the button that is pressed, and when the CHANGE_GEAR button is pressed, the car should stop and wait until the user presses either the automatic or manual mode button.
I provided a little sudo code as to how I am thinking of using the IR remote to control the car and change the modes. I would appreciate any help with trying to figure this out.
#include<IRremote.h>
#define IR_PIN 4
IRrecv IR(IR_PIN);
decode_results results;
//button Codes
#define ADVANCE 0x00FF18E7 //code from IR controller "^" button
#define BACK 0x00FF4AB5 //code from IR controller "v" button
#define RIGHT 0x00FF5AA5 //code from IR controller ">" button
#define LEFT 0x00FF10EF //code from IR controller "<" button
#define STOP_ 0x00FF38C7 //code from IR controller "OK" button
#define CHANGE_GEAR 0x00FFA857 //code from IR controller "8" button
#define AUTOMATIC 0x00FFA25D //code from IR controller "1" button
#define MANUAL 0x00FFE21D //code from IR controller "3" button
unsigned long LastCommand;
void setup() {
Serial.begin(9600);
pinMode(IR_PIN, INPUT);
digitalWrite(IR_PIN, HIGH);
IR.enableIRIn();
}
void ir_loop(){
tick = true;
if(IR.decode(&results)){
if(results.value == MANUAL){
Serial.print("MANUAL\n");
//want to stay in this if statement, and check for other button
//presses on the remote
//Ex)
//if(results.value == ADVANCE){
// Serial.print("GO FORWARD\n");
// LastCommand = results.value;
//}
//else if(results.value == LEFT){
// Serial.print("GOING LEFT\n");
// LastCommand = results.value;
//}
//and so forth until the CHANGE_GEAR button is pressed, and then
//it should exit this if statement
}
else if(results.value == AUTOMATIC){
Serial.print("AUTOMATIC\n");
LastCommand = results.value;
}
else if(results.value == 0xFFFFFFFF){
Serial.print("No valid input\n");
results.value = LastCommand;
}
results.value = 0;
IR.resume();
}
}
void loop() {
ir_loop();
}