So i started this project and I wanted to use a remote to control my robot. First let me just explain what my setup is and what hardware I am using because I am sure I'm going to have more questions. I got the Dual motor gearbox from sparkfun and the tank treads : Dual Motor GearBox - ROB-00319 - SparkFun Electronics
I plan on using the SN754410 Quad Half H-Bridge. H-Bridge Motor Driver 1A - COM-00315 - SparkFun Electronics
For my first question the hardware is not relevant. I am simply trying to turn on an led on and off with my remote that I have. When I push the up arrow on the remote once and release, I get the code: 458. then if i push it again once and release I get 10458. The code alternates each time the button is pressed and released. This is true for every button on the remote. Every button seems to have 2 codes. If I push and hold the button It will spam one of the codes, and if I release then press and hold again it spams the other code. What would be the best way to utilize these codes and the controller to drive the robot. I can think of 2 options. The first would be turn the Led High when I hold the button and to turn low when I release it. the second would be to use single key presses instead of holding the button down. For example I press up and release it which would give the code 458 and the led turns High. Then I press it again which gives 10458 and the led goes low. I dont even know how to go about the first option. I thought I knew how to code the second option but I seem to be missing something. The led wont respond to the key presses. Can someone please help me out with the code. I would like examples of both options. Here is the code I am trying to use for the second option. Thanks for any help you guys can provide.
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(13, OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
switch(results.value){
case 458:
digitalWrite(13, HIGH);
break;
case 10458:
digitalWrite(13, LOW);
}
}