Arduino ide 1.6.9 problems encountered error:’TKD2′ was not declared in this scope

Previously, I used an Arduino link to an infrared receiver to receive commands from the remote control. Control some peripherals. Using a library downloaded from Github.
I need to use it again these days. I’ve got a problem. The first error is
D:\Tools\Arduino\libraries\RobotIRremote\ SRC \ irremotetools.cpp :5:16: error: ‘TKD2’ was not declared in this scope
int RECV_PIN = TKD2; // the pin the IR receiver is connected to

            ^

Exit status 1
error for development board Arduino/Genuino Uno at compile time.
Tip me. TKD2 not found.
and then there’s the problem of finding two IRremote libraries. One of the libraries is used. So we can just delete the library that he gave the path to instead of the Arduino IDE installation directory. Write using the IRemote library provided by the Library in the Arduino IDE.
D:\Tools\Arduino\ Srtirremote \IRremoteTools. CPP :5:16: Error: ‘TKD2’ was not declared in this scope
int RECV_PIN = TKD2; // the pin the IR receiver is connected to

            ^

Exit status 1
error for development board Arduino/Genuino Uno at compile time.
I used an example of the arduino-CC remote control.
https://www.arduino.cc/en/Tutorial/RobotRemoteControl
He has too many examples. A lot I don’t need. I just want the code for his remote reception button. It is enough. But there is an error with a CPP in the library.
It looks like a CPP in the Library provided by Arduino IDE has an error. As a result. Open it up.
opens the CPP file prompted by the error.
D:\Tools\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp

#include "IRremote.h"
#include "IRremoteTools.h"
#include <Arduino.h>

int RECV_PIN = TKD2; // the pin the IR receiver is connected to
IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object
decode_results results; // container for received IR codes

void beginIRremote(){
    irrecv.enableIRIn(); // Start the receiver
}

bool IRrecived(){
    return irrecv.decode(&results);
}

void resumeIRremote(){
    irrecv.resume(); // resume receiver
}

unsigned long getIRresult(){
    return results.value;
}

We found out he had this thing called TKD2. But there’s no declaration or define on it and then we’re going to look for his H header file.

#ifndef IRREMOTETOOLS_H
#define IRREMOTETOOLS_H

extern void beginIRremote();

extern bool IRrecived();

extern void resumeIRremote();

extern unsigned long getIRresult();

#endif

There is no declaration of TKD2
Then move on to D:\Tools\Arduino\libraries\RobotIRremote\ SRC \ irremotetools.cpp
to find the introduced.h header files. Let’s see if we have TKD2.
however. I am!

#include "IRremote.h"
#include "IRremoteTools.h"

I looked for both of them. There’s no such thing as TKD2. As for the

#include <Arduino.h>

You don’t have to look for this one. Because that’s what the Arduino environment comes with. The external library is definitely not going to have a variable or define in there.
so we come to the conclusion that there is a problem with the library code provided by the arduinio ide??Lie to me. I don’t read much. But as far as we can find out, the reason is that the library file code provided by his official is wrong… All right.
I went to the official place to get feedback. I did a little bit of searching. Some people say that 1.6.7 has this problem.
however. They either use something they don’t know why. Or code not written in the official tutorial. Then there are some messages and replies and so on that don’t make sense.
and of course I’m going to talk about it here. I got this error right here. Arduino.cc is a copy and paste of the code from the official arduino.CC tutorial. And check for basic syntax errors. Compile and you get this error

error: 'TKD2' was not declared in this scope

Arduino. Cc official remote library tutorial
https://www.arduino.cc/en/Tutorial/RobotRemoteControl
Let me just copy and paste it again. There’s still this mistake.
Ah. Let’s just do it ourselves. It’s easier.
We have two ways to solve this problem.
the first type:
modifier this CPP
D:\Tools\Arduino\libraries\RobotIRremote\ SRC \ irremotetools.cpp
bar

#include "IRremote.h"
#include "IRremoteTools.h"
#include <Arduino.h>

int RECV_PIN = TKD2; // the pin the IR receiver is connected to
IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object
decode_results results; // container for received IR codes

void beginIRremote(){
    irrecv.enableIRIn(); // Start the receiver
}

bool IRrecived(){
    return irrecv.decode(&results);
}

void resumeIRremote(){
    irrecv.resume(); // resume receiver
}

unsigned long getIRresult(){
    return results.value;
}

Change TKD2 inside to 11 or the IO port on the data receiving port that you use to plug into the infrared receiver header to
to look like this

#include "IRremote.h"
#include "IRremoteTools.h"
#include <Arduino.h>

int RECV_PIN = 11; // the pin the IR receiver is connected to
IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object
decode_results results; // container for received IR codes

void beginIRremote(){
    irrecv.enableIRIn(); // Start the receiver
}

bool IRrecived(){
    return irrecv.decode(&results);
}

void resumeIRremote(){
    irrecv.resume(); // resume receiver
}

unsigned long getIRresult(){
    return results.value;
}

I changed it to 11
Of course. So if you need to modify the port. Also modify the CPP file for the library of the Arduino IDE’s library. This is a bit of bull. Let’s do the second amendment.
second method. It’s written in C++ syntax.
of course. You can just copy my code.
modified
D:\Tools\Arduino\libraries\RobotIRremote\ SRC \ irremotetools.h

#ifndef IRREMOTETOOLS_H
#define IRREMOTETOOLS_H

extern void beginIRremote();

extern bool IRrecived();

extern void resumeIRremote();

extern unsigned long getIRresult();

#endif

Change the h file to

#ifndef IRREMOTETOOLS_H
#define IRREMOTETOOLS_H

extern void beginIRremote( int receivePin );

extern bool IRrecived();

extern void resumeIRremote();

extern unsigned long getIRresult();

#endif

It is an extern void beginIRremote(int receivePin);
this method adds a parameter
. Then we modify
D:\Tools\Arduino\libraries\RobotIRremote\ SRC \ irremotetools.cpp

#include "IRremote.h"
#include "IRremoteTools.h"
#include <Arduino.h>

int RECV_PIN = TKD2; // the pin the IR receiver is connected to
IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object
decode_results results; // container for received IR codes

void beginIRremote(){
    irrecv.enableIRIn(); // Start the receiver
}

bool IRrecived(){
    return irrecv.decode(&results);
}

void resumeIRremote(){
    irrecv.resume(); // resume receiver
}

unsigned long getIRresult(){
    return results.value;
}

to

#include "IRremote.h"
#include "IRremoteTools.h"
#include <Arduino.h>

//int RECV_PIN = TKD2; // the pin the IR receiver is connected to
//IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object
IRrecv *irr;
decode_results results; // container for received IR codes

void beginIRremote( int receivePin ){
    //irrecv.enableIRIn(); // Start the receiver
    irr = new IRrecv( receivePin );
    irr->enableIRIn(); 
}

bool IRrecived(){
    //return irrecv.decode(&results);
    return irr->decode(&results);
}

void resumeIRremote(){
    //irrecv.resume(); // resume receiver
    irr->resume();
}

unsigned long getIRresult(){
    return results.value;
}

All right. And then you fix it. Let’s look at the code we’re using

#include <IRremote.h>
#include <IRremoteTools.h>

void setup() {
  Serial.begin(9600);

  beginIRremote(11); // Start the receiver
}

void loop() {
  if (IRrecived()) {
    unsigned long res = getIRresult();
    Serial.println( res );
    resumeIRremote(); // resume receiver
  }
}

Then compile


The project uses 4,772 bytes and takes up (14%) of program memory. The maximum is 32,256 bytes.
Global variables use 432 bytes, (21%) of dynamic memory, leaving 1,616 bytes for local variables. The maximum is 2,048 bytes.

OK, that’s it.
Once again given the arduino. Cc official the use of remote control library tutorial address

Read More: