So I'm trying to turn an ON LED OFF or an OFF LED ON using a TV Remote. In the #define line, I write the hex code received from pressing the designated button on the TV remote. However, during compilation, an error saying unable to find numeric literal operator 'operator""DE74847'
appears. I've scoured the web and can't come up with a solution.
#include <IRremote.h>
#include <IRremoteInt.h>
int ledPin = 13;
int IRPin = 3;
#define code1 0575
IRrecv irrecv(IRPin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
unsigned int value = results.value;
int ledState = digitalRead(ledPin);
switch(value)
{
case code1:
if (ledState = HIGH)
{
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, HIGH);
}
break;
}
}
else
{
digitalWrite (ledPin, LOW);
}
unsigned int value = results.value;
Serial.println(value);
irrecv.resume();
}
Here's the code. Please help.
1 Answer 1
Your problem is that you don't know how to form hexadecimal numbers.
In your code (in future, if you have an error in the code please post the code that is causing the error, not something else entirely - it makes it nigh on impossible for people without my psychic abilities to answer your question) you have defined a macro containing what you think is a hexadecimal number. In fact it's just a random string of characters and the compiler doesn't know what to make of it:
#define code1 DE74847
So in your switch construct, when code1
gets replaced with the content of the macro, you end up with:
switch (value) {
case DE74847:
....
The compiler has no idea what a DE74847 is.
Numbers other than decimal numbers (0-9 and the decimal point) are identified by the use of a prefix:
0b...
is binary0
is octal (in your completely different code you have the number 0575, which is actually octal, and represents the decimal value 381)0x
is hexadecimal.
So adding 0x
to the start of your hexadecimal value will tell the compiler to treat it as hexadecimal:
#define code1 0xDE74847
define
. It also seems like the code you've provided is different from the code that gave the error.0x
so the compiler knows it's HEX.0575
is an octal number, not a HEX number. DE74847 is a random string of characters that it can't understand. Use0xDE74847
instead.