Hi!
I just started with Arduino and built a mini rover from DFRobotShop. I also purchased the shield that goes with this project. I followed the instructions and everything works fine. I was even able to get all the different codes from a remote control to use with the rover. The problem I have is that the instructions only provide a sample code that control the car going forward (with the push of a button from the remote). However, the code stops at that and I don’t know how to continue writing the code on the same sketch to make at least four other buttons work (i.e., backward, turn right, turn left, stop)
Here’s the sketch code (notice the whole block to make one button work; I need the code for the other four buttons (i.e., where do I start copying and modifying the code and where do I end?):
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;
int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control
void setup()
{
int i;
for(i=5;i<=8;i++)
pinMode(i, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
int leftspeed = 255; //255 is maximum speed
int rightspeed = 255;
if (irrecv.decode(&results))
{
if(results.value == 16748655) // This code will vary based on your remote control
{
analogWrite (E1,255);
digitalWrite(M1,HIGH);
analogWrite (E2,255);
digitalWrite(M2,HIGH);
delay(1000);
}
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
irrecv.resume(); // Receive the next value
}
}
Thank you so much in advance for your help!