Hey Arduino Community! I have an IR receiver that when I press the Vol+ on my remote I want it to increase the integer by 1 and when I press the Vol- it decreases the integer by 1. It seemed simple enough to implement with ++int and --int, but I have run into a couple of problems.
Here is my code so far:
//10EF01FE = VOL+
//10EF718E = VOL-
//10EFC13E = CH+(VOL +10
//10EF619E = CH-(VOL -10)
//10EF3BC4 = EXIT(MUTE)
#include <IRremote.h>
#include <SPI.h>
int RECV_PIN = 2;
int i = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
SPI.begin();
}
void loop() {
if (irrecv.decode(&results)) {
//Serial.println(results.value, HEX);
if (results.value==0x210EF01FE) {
++i;
Serial.println(i);
}
else (results.value==0x210EF718E);
{
--i;
Serial.println(i);
}
irrecv.resume(); // Receive the next value
}
delay(100);
}
So here are my 2 problems.
-
When I press ANY button on my remote it changes the value of i.
-
The value of i always counts down into the negative values.
And once I get this problem fixed, I want to increase/decrease the value by 10 using two other buttons.
HELP!!!
And Much Thanks in advance!
if (results.value==0x210EF01FE) {
++i;
Serial.println(i);
}
else (results.value==0x210EF718E);
Mucho oops
Please remember to use code tags when posting code
Sorry, this is my first time programming anything, and being on this forum.
What are code tags?
if (results.value==0x210EF01FE) {
++i;
Serial.println(i);
}
if (results.value==0x210EF718E) {
--i;
Serial.println(i);
}
Those are code tags
//10EF01FE = VOL+
//10EF718E = VOL-
results.value==0x210EF01FE
results.value==0x210EF718E
^
???
What are those twos doing there? Those comparisons will never be true.
Ah, I do see the difference in the reference, and in your post AWOL.
Thanks you guys!
So what it looks like is I don't HAVE to put an else statement when using an if. I can just keep using if statements for all my functions. Conditions can only be used with if and else if, not with else.
Am I correct in my thinking?
oqibidipo - those HEX comparisons are if statements. If the hex code from the IR receiver matches 0x210EF01FE then increment int i by 1. If the hex code from the IR receiver matches 0x210EF718E then decrease int i by 1.
ok thanks! so using else if makes the code more efficient?
I would like some clarification to oqibidipo question. I only figured it out from an example, but don't really understand the reasoning behind it. I know that I have to add 0x2 before a hexadecimal value for the program to read the hex value, but what is really going on behind the scene?
AH! that might be part of my problem...
THANKS!!